yelp.py 1021 B

1234567891011121314151617181920212223242526272829303132
  1. import simplejson as json
  2. import oauth2
  3. import requests
  4. # OAuth credential placeholders that must be filled in by users.
  5. CONSUMER_KEY = 'EXMisJNWez_PuR5pr06hyQ'
  6. CONSUMER_SECRET = 'VCK-4cDjtQ9Ra4HC5ltClNiJFXs'
  7. TOKEN = 'AWYVs7Vim7mwYyT1BLJA2xhNTs_vXLYS'
  8. TOKEN_SECRET = 'Rv4GrlYxYGhxUs14s0VBfk7JLJY'
  9. def requestData():
  10. url = 'http://api.yelp.com/v2/business/marlowe-san-francisco-2?'
  11. consumer = oauth2.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
  12. oauth_request = oauth2.Request(method="GET", url=url)
  13. oauth_request.update(
  14. {
  15. 'oauth_nonce': oauth2.generate_nonce(),
  16. 'oauth_timestamp': oauth2.generate_timestamp(),
  17. 'oauth_token': TOKEN,
  18. 'oauth_consumer_key': CONSUMER_KEY
  19. }
  20. )
  21. token = oauth2.Token(TOKEN, TOKEN_SECRET)
  22. oauth_request.sign_request(oauth2.SignatureMethod_HMAC_SHA1(), consumer, token)
  23. signed_url = oauth_request.to_url()
  24. req = requests.get(signed_url)
  25. content = json.loads(req.content)
  26. return content