From 5632f1d30d231449e6174f3f9860cda6ab5ae4d2 Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Fri, 1 May 2015 11:27:42 -0700 Subject: [PATCH] reformatted/tweaked and added the examples from example.py in the yelpapi package --- .gitignore | 2 ++ yelp1-json.py | 14 ++++++++++++++ yelp1.py | 18 ++++++++++++++++++ yelp2-json.py | 16 ++++++++++++++++ yelp2.py | 18 ++++++++++++++++++ yelp3-json.py | 13 +++++++++++++ yelp3.py | 16 ++++++++++++++++ yelp_authentication.py | 4 ++++ 8 files changed, 101 insertions(+) create mode 100644 .gitignore create mode 100644 yelp1-json.py create mode 100644 yelp1.py create mode 100644 yelp2-json.py create mode 100644 yelp2.py create mode 100644 yelp3-json.py create mode 100644 yelp3.py create mode 100644 yelp_authentication.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6add511 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*~ \ No newline at end of file diff --git a/yelp1-json.py b/yelp1-json.py new file mode 100644 index 0000000..88f370c --- /dev/null +++ b/yelp1-json.py @@ -0,0 +1,14 @@ +from yelpapi import YelpAPI +from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET + +yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET) + +# Example search by location text and term. Take a look at +# http://www.yelp.com/developers/documentation/v2/search_api for +# the various options available. + +# print the 5 best rated ice cream places in Austin, TX + +response = yelp_api.search_query(term='ice cream', location='austin, tx', sort=2, limit=5) + +print(response) diff --git a/yelp1.py b/yelp1.py new file mode 100644 index 0000000..454f54d --- /dev/null +++ b/yelp1.py @@ -0,0 +1,18 @@ +from yelpapi import YelpAPI +from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET + +yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET) + +# Example search by location text and term. Take a look at +# http://www.yelp.com/developers/documentation/v2/search_api for +# the various options available. + +print('***** 5 best rated ice cream places in Austin, TX *****') + +response = yelp_api.search_query(term='ice cream', location='austin, tx', sort=2, limit=5) + +print('region center (lat,long): %s,%s\n' % (response['region']['center']['latitude'], response['region']['center']['longitude'])) + +for business in response['businesses']: + print('%s\n\tYelp ID: %s\n\trating: %g (%d reviews)\n\taddress: %s' % (business['name'], business['id'], business['rating'], business['review_count'], ', '.join(business['location']['display_address']))) + diff --git a/yelp2-json.py b/yelp2-json.py new file mode 100644 index 0000000..0d2d0c5 --- /dev/null +++ b/yelp2-json.py @@ -0,0 +1,16 @@ +from yelpapi import YelpAPI +from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET + +yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET) + +# Example search by bounding box and category. See +# http://www.yelp.com/developers/documentation/v2/all_category_list +# for an official list of Yelp categories. The bounding box definition +# comes from +# http://isithackday.com/geoplanet-explorer/index.php?woeid=12587707. + +# 5 bike rentals in San Francisco county + +response = yelp_api.search_query(category_filter='bikerentals', bounds='37.678799,-123.125740|37.832371,-122.356979', limit=5) + +print(response) diff --git a/yelp2.py b/yelp2.py new file mode 100644 index 0000000..ff55338 --- /dev/null +++ b/yelp2.py @@ -0,0 +1,18 @@ +from yelpapi import YelpAPI +from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET + +yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET) + +# Example search by bounding box and category. See +# http://www.yelp.com/developers/documentation/v2/all_category_list +# for an official list of Yelp categories. The bounding box definition +# comes from +# http://isithackday.com/geoplanet-explorer/index.php?woeid=12587707. + +print('***** 5 bike rentals in San Francisco county *****') + +response = yelp_api.search_query(category_filter='bikerentals', bounds='37.678799,-123.125740|37.832371,-122.356979', limit=5) + +for business in response['businesses']: + print('%s\n\tYelp ID: %s\n\trating: %g (%d reviews)\n\taddress: %s' % (business['name'], business['id'], business['rating'], + business['review_count'], ', '.join(business['location']['display_address']))) diff --git a/yelp3-json.py b/yelp3-json.py new file mode 100644 index 0000000..06c814d --- /dev/null +++ b/yelp3-json.py @@ -0,0 +1,13 @@ +from yelpapi import YelpAPI +from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET + +yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET) + +# Example business query. Look at +# http://www.yelp.com/developers/documentation/v2/business for more +# information. + +business = yelp_api.business_query(id='amys-ice-creams-austin-3') +print(business) + + diff --git a/yelp3.py b/yelp3.py new file mode 100644 index 0000000..51dbcde --- /dev/null +++ b/yelp3.py @@ -0,0 +1,16 @@ +from yelpapi import YelpAPI +from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET + +yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET) + +# Example business query. Look at +# http://www.yelp.com/developers/documentation/v2/business for more +# information. + +print("***** selected reviews for Amy's on 6th St. *****") + +business = yelp_api.business_query(id='amys-ice-creams-austin-3') + +for review in business['reviews']: + print('rating: %d\nexcerpt: %s\n' % (review['rating'], review['excerpt'])) + diff --git a/yelp_authentication.py b/yelp_authentication.py new file mode 100644 index 0000000..bc817e5 --- /dev/null +++ b/yelp_authentication.py @@ -0,0 +1,4 @@ +CONSUMER_KEY = 'CHANGE_ME' +CONSUMER_SECRET = 'CHANGE_ME' +TOKEN = 'CHANGE_ME' +TOKEN_SECRET = 'CHANGE_ME' -- 2.30.2