Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions fusion/python/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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')
Copy link
Contributor

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?

Copy link
Contributor

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

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'
Copy link
Contributor

Choose a reason for hiding this comment

The 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


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you undo the changes to query_api ? This is supposed to be a very basic example program, just printing the top result keeps the example simple and easy to read, adding more complicated logic distracts from the functionality it is trying to highlight

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():
Expand Down Expand Up @@ -205,3 +215,6 @@ def main():

if __name__ == '__main__':
main()

Copy link
Contributor

Choose a reason for hiding this comment

The 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')