-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample17.py
80 lines (73 loc) · 2.36 KB
/
example17.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import json
import httplib
import pprint
from sys import exit
hostName = "data.cityofchicago.org"
service = "/views/INLINE/rows"
formatType = "json"
parameters = "method=index"
headers = { "Content-type:" : "application/json" }
query = {
"originalViewId": "7as2-ds3y",
"name": "Nearby potholes",
"query": {
"filterCondition": {
"type": "operator",
"value": "AND",
"children": [
{
"children": [
{
"type": "operator",
"value": "within_circle",
"metadata": {
"freeform": "true"
},
"children": [
{
"type": "column",
"columnId": 2793590
},
{
"type": "literal",
"value": 41.9249
},
{
"type": "literal",
"value": -87.6876
},
{
"type": "literal",
"value": 100
}
]
}
],
"type": "operator",
"value": "OR"
}
]
}
}
}
jsonQuery = json.dumps(query)
request = service + '.' + formatType + '?' + parameters
conn = httplib.HTTPConnection(hostName)
conn.request("POST", request, jsonQuery, headers)
response = conn.getresponse()
if response.reason != 'OK':
print "There was an error detected."
print "Response status = %s.\n" % response.status
print "Response reason = %s.\n" % response.reason
raise SystemExit(1)
rawResponse = response.read()
jsonResponse = json.loads(rawResponse)
rowNum = 1
for rowData in jsonResponse['data']:
print "\n===== Row %d ====" % (rowNum)
colNum = 0
for columnMeta in jsonResponse['meta']['view']['columns']:
if columnMeta['id'] > 0:
print columnMeta['name'], ' = ', rowData[colNum]
colNum += 1
rowNum += 1