|
@@ -1,3 +1,11 @@
|
|
|
|
|
+# pylint: disable=invalid-name
|
|
|
|
|
+
|
|
|
|
|
+'''
|
|
|
|
|
+Yelp.py contains methods for
|
|
|
|
|
+authenticating the user and
|
|
|
|
|
+retrieving data from Yelp's API.
|
|
|
|
|
+'''
|
|
|
|
|
+
|
|
|
import simplejson as json
|
|
import simplejson as json
|
|
|
import oauth2
|
|
import oauth2
|
|
|
import requests
|
|
import requests
|
|
@@ -9,6 +17,10 @@ TOKEN = 'AWYVs7Vim7mwYyT1BLJA2xhNTs_vXLYS'
|
|
|
TOKEN_SECRET = 'Rv4GrlYxYGhxUs14s0VBfk7JLJY'
|
|
TOKEN_SECRET = 'Rv4GrlYxYGhxUs14s0VBfk7JLJY'
|
|
|
|
|
|
|
|
def requestData(location):
|
|
def requestData(location):
|
|
|
|
|
+ '''
|
|
|
|
|
+ Authenticates a request and returns
|
|
|
|
|
+ data from Yelp API.
|
|
|
|
|
+ '''
|
|
|
data = []
|
|
data = []
|
|
|
url = 'http://api.yelp.com/v2/business/' + location + '?'
|
|
url = 'http://api.yelp.com/v2/business/' + location + '?'
|
|
|
|
|
|
|
@@ -26,9 +38,7 @@ def requestData(location):
|
|
|
token = oauth2.Token(TOKEN, TOKEN_SECRET)
|
|
token = oauth2.Token(TOKEN, TOKEN_SECRET)
|
|
|
oauth_request.sign_request(oauth2.SignatureMethod_HMAC_SHA1(), consumer, token)
|
|
oauth_request.sign_request(oauth2.SignatureMethod_HMAC_SHA1(), consumer, token)
|
|
|
signed_url = oauth_request.to_url()
|
|
signed_url = oauth_request.to_url()
|
|
|
-
|
|
|
|
|
req = requests.get(signed_url)
|
|
req = requests.get(signed_url)
|
|
|
content = json.loads(req.content)
|
|
content = json.loads(req.content)
|
|
|
data.append(content)
|
|
data.append(content)
|
|
|
-
|
|
|
|
|
- return data
|
|
|
|
|
|
|
+ return data
|