-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-consumer.py
37 lines (30 loc) · 1.1 KB
/
api-consumer.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
import json
import urllib2
# change this url to
API_KEY = "YOUR_API"
# change this url to filter
url = "https://api.dandelion.eu/datagems/v2/SpazioDati/milanotoday/data?$offset=0&$app_id=%s&$app_key=%s" % (API_KEY,API_KEY)
response = urllib2.urlopen(url);
json_response = json.load( response )
items = json_response['items']
rows = []
for item in items:
row = ""
row += (u'%s\t' % (item['title']))
row += (u'%s\t' % (item['link']))
row += (u'%s\t' % (item['model']))
row += (u'%s\t' % (item['topic']))
row += (u'%s\t' % (item['date']))
row += (u'%s\t' % (item['timestamp']))
row += (u'%s\t' % (item['municipality']['acheneID']))
row += (u'%s\t' % (item['municipality']['name']))
row += (u'%s\t' % (item['address']))
row += (u'%s\t' % (item['location']))
row += (u'%s\t' % (item['geometry']['type'] if(item['geometry']) else ""))
row += (u'%s\t' % (item['geometry']['coordinates'][0] if(item['geometry']) else "-1") )
row += (u'%s' % (item['geometry']['coordinates'][1] if(item['geometry']) else "-1") )
e = row.encode('utf-8')
rows.append(e)
f = open('news.csv','w+')
f.write("\n".join(rows))
f.close()