Skip to content

Instantly share code, notes, and snippets.

@desg
Created May 6, 2014 01:13
Show Gist options
  • Save desg/fc25324cf713fe08beb5 to your computer and use it in GitHub Desktop.
Save desg/fc25324cf713fe08beb5 to your computer and use it in GitHub Desktop.
import requests
from requests_oauthlib import OAuth1
import random
#API information
consumer_key = ""
consumer_secret = ""
token = ""
token_secret = ""
# Write Better Version of this
foodsURL = "http://api.yelp.com/v2/search?"
term = "food"
radius_filter ="16100"
location = "Atlanta"
payload = {'term': term, 'radius_filter': radius_filter, 'location': location}
def yelpRequest(hostURL, payload, consumer_key, consumer_secret, token, token_secret):
auth = OAuth1(consumer_key, consumer_secret,
token, token_secret)
con = requests.get(hostURL, params=payload, auth=auth).json()
return con
response = yelpRequest(foodsURL, payload, consumer_key, consumer_secret, token,
token_secret)
foodlist = []
for i in range(0, len(response['businesses'])):
foodlist.append(response['businesses'][i]#['name'].encode('utf_8'))
print random.choice(foodlist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment