]> projects.mako.cc - yelp-api-cdsw/commitdiff
reformatted/tweaked and added the examples from example.py in the yelpapi package
authorBenjamin Mako Hill <mako@atdot.cc>
Fri, 1 May 2015 18:27:42 +0000 (11:27 -0700)
committerBenjamin Mako Hill <mako@atdot.cc>
Fri, 1 May 2015 18:27:42 +0000 (11:27 -0700)
.gitignore [new file with mode: 0644]
yelp1-json.py [new file with mode: 0644]
yelp1.py [new file with mode: 0644]
yelp2-json.py [new file with mode: 0644]
yelp2.py [new file with mode: 0644]
yelp3-json.py [new file with mode: 0644]
yelp3.py [new file with mode: 0644]
yelp_authentication.py [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..6add511
--- /dev/null
@@ -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 (file)
index 0000000..88f370c
--- /dev/null
@@ -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 (file)
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 (file)
index 0000000..0d2d0c5
--- /dev/null
@@ -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 (file)
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 (file)
index 0000000..06c814d
--- /dev/null
@@ -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 (file)
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 (file)
index 0000000..bc817e5
--- /dev/null
@@ -0,0 +1,4 @@
+CONSUMER_KEY = 'CHANGE_ME'
+CONSUMER_SECRET = 'CHANGE_ME'
+TOKEN = 'CHANGE_ME'
+TOKEN_SECRET = 'CHANGE_ME'

Benjamin Mako Hill || Want to submit a patch?