-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parse_requests.py
47 lines (36 loc) · 1.36 KB
/
Parse_requests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
__author__ = 'Bryce Langlotz'
import sys
import json,httplib
allReviews = []
reviewsForRestaurant = []
def getBusinesses():
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('GET', '/1/classes/Restaurants', '', {
"X-Parse-Application-Id": "aS5JfOEzT7lLooye3NQCzkFQagbUXaQVhKX24wnE",
"X-Parse-REST-API-Key": "N6SrV95BxIw970IsSLBYBdM4ik0dWFtTRhC3HYCx"
})
data = json.loads(connection.getresponse().read())
return data["results"]
def getReviewsForBusiness(business):
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('GET', '/1/classes/' + business, '', {
"X-Parse-Application-Id": "aS5JfOEzT7lLooye3NQCzkFQagbUXaQVhKX24wnE",
"X-Parse-REST-API-Key": "N6SrV95BxIw970IsSLBYBdM4ik0dWFtTRhC3HYCx"
})
data = json.loads(connection.getresponse().read())
return data["results"]
def getAllReviews():
reviewCollection = []
restaurants = getBusinesses()
for restaurant in restaurants:
reviews = getReviewsForBusiness(restaurant["alpha_numeric_name"])
reviewCollection += reviews
return reviewCollection
if len(sys.argv) == 1:
allReviews = getAllReviews()
print(allReviews)
else:
reviewsForRestaurant = getReviewsForBusiness(str(sys.argv[1]))
print(reviewsForRestaurant)