SHARE
TWEET

Coding with Python: API Basics

codingentrepreneurs Feb 12th, 2014 7,239 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. #Learn how this works here: http://youtu.be/pxofwuWTs7c
  3.  
  4. import urllib2
  5. import json
  6.  
  7. locu_api = 'YOUR KEY HERE'
  8.  
  9. def locu_search(query):
  10.     api_key = locu_api
  11.     url = 'https://api.locu.com/v1_0/venue/search/?api_key=' + api_key
  12.     locality = query.replace(' ', '%20')
  13.     final_url = url + "&locality=" + locality + "&category=restaurant"
  14.     json_obj = urllib2.urlopen(final_url)
  15.     data = json.load(json_obj)
  16.    
  17.     for item in data['objects']:
  18.         print item['name'], item['phone']
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top