-
Notifications
You must be signed in to change notification settings - Fork 0
/
listRestaurants.py
62 lines (49 loc) · 1.46 KB
/
listRestaurants.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import requests
import urllib2
import urllib
import json
from bottle import *
def JSONgetter(id,cidade,count):
#Lx - id 82
#Porto - id 311
if cidade=="Lisboa":
id=82
if cidade=="Porto":
id=311
url = "https://developers.zomato.com/api/v2.1/search?entity_id="+str(id)+"&entity_type=city&count="+str(count)
querystring = {"q":cidade}
headers = {
'user_key': "56057f6401e8a354b5a5287d0b5f75c1",
'cache-control': "no-cache"
}
# create the request object and set some headers
req = urllib2.Request(url)
req.add_header('Accept', 'application/json')
req.add_header("Content-type", "application/json, charset=utf-8")
req.add_header('user_key', "56057f6401e8a354b5a5287d0b5f75c1")
# make the request and print the results
res = urllib2.urlopen(req)
#print json.loads(aux)
#print "---------------------------------------------"
data = json.load(res)
aux = json.dumps(data,ensure_ascii=False,encoding='utf8')
return aux
#print JSONgetter()
import sys
# simple argument echo script to expose Python output to JS
list =[]
for i in sys.argv[1:]:
list.append(i)
data = JSONgetter(list[0],list[1],list[2])
print data
"""
corrected_data = {}
for k, v in data.iteritems():
corrected_data[k] = unicode(v).encode('utf-8')
dataFinal = urllib.urlencode(corrected_data)
print dataFinal
"""