-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sample.py lists all the results found and takes credentials from a co… #283
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
Sample usage of the program: | ||
`python sample.py --term="bars" --location="San Francisco, CA"` | ||
""" | ||
|
||
|
||
from __future__ import print_function | ||
|
||
import argparse | ||
|
@@ -24,6 +26,7 @@ | |
import requests | ||
import sys | ||
import urllib | ||
import configparser | ||
|
||
|
||
# This client code can run on Python 2.x or 3.x. Your imports can be | ||
|
@@ -43,21 +46,23 @@ | |
# OAuth credential placeholders that must be filled in by users. | ||
# You can find them on | ||
# https://www.yelp.com/developers/v3/manage_app | ||
CLIENT_ID = None | ||
CLIENT_SECRET = None | ||
|
||
config = configparser.RawConfigParser() | ||
config.read('API_Keys.cfg') | ||
CLIENT_ID = config.get('Yelp', 'CLIENT_ID') | ||
CLIENT_SECRET = config.get('Yelp', 'CLIENT_SECRET') | ||
|
||
# API constants, you shouldn't have to change these. | ||
API_HOST = 'https://api.yelp.com' | ||
SEARCH_PATH = '/v3/businesses/search' | ||
BUSINESS_PATH = '/v3/businesses/' # Business ID will come after slash. | ||
TOKEN_PATH = '/oauth2/token' | ||
PHONE_PATH = '/v3/businesses/search/phone' | ||
GRANT_TYPE = 'client_credentials' | ||
|
||
|
||
# Defaults for our simple example. | ||
DEFAULT_TERM = 'dinner' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we leave the term being a generic search? Makes it more relatable |
||
DEFAULT_LOCATION = 'San Francisco, CA' | ||
DEFAULT_TERM = 'WELLER, CHANA' | ||
DEFAULT_LOCATION = '10024' | ||
SEARCH_LIMIT = 3 | ||
|
||
|
||
|
@@ -133,8 +138,10 @@ def search(bearer_token, term, location): | |
url_params = { | ||
'term': term.replace(' ', '+'), | ||
'location': location.replace(' ', '+'), | ||
'limit': SEARCH_LIMIT | ||
'limit': SEARCH_LIMIT, | ||
'radius': 3000 | ||
} | ||
|
||
return request(API_HOST, SEARCH_PATH, bearer_token, url_params=url_params) | ||
|
||
|
||
|
@@ -174,10 +181,13 @@ def query_api(term, location): | |
print(u'{0} businesses found, querying business info ' \ | ||
'for the top result "{1}" ...'.format( | ||
len(businesses), business_id)) | ||
response = get_business(bearer_token, business_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you undo the changes to |
||
out= [] | ||
print(type(out)) | ||
for i in range(len(businesses)): | ||
out.append(get_business(bearer_token, businesses[i]['id'])) | ||
|
||
print(u'Result for business "{0}" found:'.format(business_id)) | ||
pprint.pprint(response, indent=2) | ||
print('\033[93m' + u'Result for business "{0}" found:'.format(businesses[i]['id']) + '\033[0m') | ||
pprint.pprint(out[i], indent=2) | ||
|
||
|
||
def main(): | ||
|
@@ -205,3 +215,6 @@ def main(): | |
|
||
if __name__ == '__main__': | ||
main() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment below isn't providing much, could you delete it please |
||
# Example: | ||
##query_api('Levingart Garry','New York, NY') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you include a default
API_Keys.cfg
with bogus values?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please don't forget to update it to use an API_KEY rather than CLIENT_ID / CLIENT_SECRET, more details here