mk200789 il y a 10 ans
Parent
commit
9fd3d2db43

+ 32 - 0
hackathon_starter/hackathon/scripts/yelp.py

@@ -0,0 +1,32 @@
+import simplejson as json
+import oauth2
+import requests
+
+# OAuth credential placeholders that must be filled in by users.
+CONSUMER_KEY = 'EXMisJNWez_PuR5pr06hyQ'
+CONSUMER_SECRET = 'VCK-4cDjtQ9Ra4HC5ltClNiJFXs'
+TOKEN = 'AWYVs7Vim7mwYyT1BLJA2xhNTs_vXLYS'
+TOKEN_SECRET = 'Rv4GrlYxYGhxUs14s0VBfk7JLJY'
+
+def requestData():
+    url = 'http://api.yelp.com/v2/business/marlowe-san-francisco-2?'
+
+    consumer = oauth2.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
+    oauth_request = oauth2.Request(method="GET", url=url)
+
+    oauth_request.update(
+        {
+            'oauth_nonce': oauth2.generate_nonce(),
+            'oauth_timestamp': oauth2.generate_timestamp(),
+            'oauth_token': TOKEN,
+            'oauth_consumer_key': CONSUMER_KEY
+        }
+    )
+    token = oauth2.Token(TOKEN, TOKEN_SECRET)
+    oauth_request.sign_request(oauth2.SignatureMethod_HMAC_SHA1(), consumer, token)
+    signed_url = oauth_request.to_url()
+    
+    req = requests.get(signed_url)
+    content = json.loads(req.content)
+
+    return content

+ 1 - 0
hackathon_starter/hackathon/templates/hackathon/api_examples.html

@@ -16,6 +16,7 @@
 		<div class="col-sm-4"><a href="http://127.0.0.1:8000/hackathon/twitterTweets/">Twitter Tweet Example</a></div>
 		<div class="col-sm-4"><a href="http://localhost:8000/hackathon/quandlstocks/">Quandl Example</a></div>
 		<div class="col-sm-4"><a href="http://localhost:8000/hackathon/meetupUser/">Meetup</a></div>
+		<div class="col-sm-4"><a href="http://localhost:8000/hackathon/yelp/">Yelp</a></div>
 
   	</div>
 

+ 1 - 0
hackathon_starter/hackathon/templates/hackathon/yelp.html

@@ -0,0 +1 @@
+{{ data }} 

+ 1 - 0
hackathon_starter/hackathon/urls.py

@@ -37,4 +37,5 @@ urlpatterns = patterns('',
     url(r'^meetup/$', views.meetup, name='meetup'),
     url(r'^meetupToken/$', views.meetupToken, name='meetupToken'),
     url(r'^meetupUser/$', views.meetupUser, name='meetupUser'),
+    url(r'^yelp/$', views.yelp, name='yelp'),
 )

+ 10 - 0
hackathon_starter/hackathon/views.py

@@ -23,6 +23,7 @@ from scripts.twitter import TwitterOauthClient
 from scripts.nytimes import *
 from scripts.meetup import *
 from scripts.linkedin import LinkedInAPI
+from scripts.yelp import requestData
 
 # Python
 import oauth2 as oauth
@@ -140,6 +141,15 @@ def facebook(request):
     yourappid = '364831617044713'
     return render(request, 'hackathon/facebook.html', { 'yourappid' : yourappid })
 
+
+#################
+#    YELP API   #
+#################
+
+def yelp(request):
+    data = requestData()
+    return render(request, 'hackathon/yelp.html', { 'data': data })
+
 #################
 #   MEETUP API  #
 #################

+ 5 - 0
hackathon_starter/hackathon_starter/settings.py

@@ -134,3 +134,8 @@ LINKEDIN_API_KEY = '7895bbnlh1k0mn'
 LINKEDIN_SECRET_KEY = '7CjUx1xTsF2WDRAI'
 LINKEDIN_USER_TOKEN = '806caefc-84a9-40cd-a706-445b08afec02'
 LINKEDIN_USER_SECRET = '7c0e25c3-d858-4c36-8c6e-a787403bb59b'
+
+YELP_CONSUMER_KEY = 'EXMisJNWez_PuR5pr06hyQ'
+YELP_CONSUMER_SECRET = 'VCK-4cDjtQ9Ra4HC5ltClNiJFXs'
+YELP_TOKEN = 'AWYVs7Vim7mwYyT1BLJA2xhNTs_vXLYS'
+YELP_TOKEN_SECRET = 'Rv4GrlYxYGhxUs14s0VBfk7JLJY'