-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-add-sensor.py
executable file
·70 lines (57 loc) · 1.88 KB
/
user-add-sensor.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
#!/usr/bin/env python
# # -*- coding: utf-8 -*-
""" Smogdance
An open-source collection of scripts to collect, store and graph air quality data
from publicly available sources.
This walks the user through a new sensor creation. This is good for adding
single sensors, or creating a template that can be copied and edited
to add dozens of sensors at once.
gnd, 2017 - 2018
"""
import os
import sys
import pickle
import ConfigParser
### load config
settings_file = os.path.join(sys.path[0], 'settings_python')
config = ConfigParser.ConfigParser()
config.readfp(open(settings_file))
DATA_DIR = config.get('globals', 'DATA_DIR')
name = raw_input("Sensor name:")
link_src = raw_input("Sensor source link:")
link_web = raw_input("Sensor web link:")
link_stat=""
substances=[]
xpaths=[]
modifiers=[]
more = False
while not more:
tmp_substance = raw_input("Substance: (enter n for no more)")
if tmp_substance == "n" or tmp_substance =="":
more = True
else:
substances.append(tmp_substance)
sql_substances = ""
for substance in substances:
xpaths.append(raw_input(substance+" xpath:"))
modifiers.append(raw_input(substance+" modifier:"))
sql_substances += substance + " "
tmp = ""
sensor_xpaths = ""
for i in range(len(substances)):
tmp = ""
tmp += substances[i] + "--"
tmp += xpaths[i] + "--"
tmp += modifiers[i] + ";"
sensor_xpaths += tmp
sensor_xpaths = sensor_xpaths.strip(";")
country = raw_input("Coutry:")
city = raw_input("City:")
gps = raw_input("GPS:")
gps = gps.replace(" sš","").replace(" vd","")
type = raw_input("Type:")
print "Running add sensor..."
script = "%s/%s" % (DATA_DIR, "add-sensor.py")
command = "%s \'%s\' \'%s\' \'%s\' \'%s\' \'%s\' \'%s\' \'%s\' \'%s\' \'%s\' \'%s\'" % (script, name, link_src, link_web, "", sensor_xpaths, country, city, gps, type, sql_substances.strip())
print command
os.system(command)