-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLAM_stations.py
64 lines (52 loc) · 1.87 KB
/
LAM_stations.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
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 14 10:31:38 2017
@author: Zan
"""
import requests # Load LAM data and parse JSON result
# Helper functions
# List available measurement stations with some metadata
def list_stations():
list_url = 'https://tie.digitraffic.fi/api/v1/metadata/tms-stations?lastUpdated=false&state=active'
resp = requests.get(url=list_url)
data = resp.json()
print 'ID;Name;Direction1;Direction2;Coordinates'
for feature in data[u'features']:
descr = str(feature[u'id']) + ';'
try:
descr += feature[u'properties'][u'names'][u'fi'] + ';'
except:
descr += 'NA;'
try:
descr += feature[u'properties'][u'direction1Municipality'] + ';'
except:
descr += 'NA;'
try:
descr += feature[u'properties'][u'direction2Municipality'] + ';'
except:
descr += 'NA;'
try:
descr += str(feature[u'geometry'][u'coordinates'])
except:
descr += 'NA'
try:
print descr
except:
print "Unicode error"
# List available cameras with some metadata
def list_cameras():
list_url = 'https://tie.digitraffic.fi/api/v1/metadata/camera-stations?lastUpdated=false'
resp = requests.get(url=list_url)
data = resp.json()
#print data
print 'ID;Name;Direction;Coordinates;URL'
for feature in data[u'features']:
try:
for preset in feature[u'properties'][u'presets']:
if preset[u'inCollection']: # Only list active ones
print str(feature[u'id']) + ';' + feature[u'properties'][u'names'][u'fi'] + ';' + preset[u'presentationName'] + ';' + \
str(feature[u'properties'][u'coordinatesETRS89']) + ';' + preset[u'imageUrl']
except:
# If some fields are missing, forget it
pass
list_stations()