-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert2snippets.py
48 lines (38 loc) · 1.61 KB
/
convert2snippets.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
import json
with open('coins.json') as f:
data = json.load(f)
outputForTimeline = open('coins-with-time.json.txt', 'w')
outputForMap = open('coins-with-coordinates.json.txt', 'w')
# We're counting items and images (for geo and time dumps) for info
geoItemCounter = 0
geoImageCounter = 0
timeItemCounter = 0
timeImageCounter = 0
for item in data['items']:
geoItemCounter += 1
geoImageCounter += len(item['depictions'])
converted = {
'title': item['title'],
'provider': item['dataset_path'][0]['title'],
'homepage': item['homepage'],
'image_urls': item['depictions'],
'geo_bounds': {
'min_lon': item['geo_bounds']['min_lon'],
'max_lon': item['geo_bounds']['max_lon'],
'min_lat': item['geo_bounds']['min_lat'],
'max_lat': item['geo_bounds']['max_lat']
}
}
if 'temporal_bounds' in item:
timeItemCounter += 1
timeImageCounter += len(item['depictions'])
converted['temporal_bounds'] = { 'from': item['temporal_bounds']['start'], 'to': item['temporal_bounds']['end'] }
outputForTimeline.write(json.dumps(converted))
outputForTimeline.write('\n')
outputForMap.write(json.dumps(converted))
outputForMap.write('\n')
outputForTimeline.close()
outputForMap.close()
print('Converted:')
print(str(geoItemCounter) + ' items with ' + str(geoImageCounter) + ' images')
print('With date: ' + str(timeItemCounter) + ' items with ' + str(timeImageCounter) + ' images')