-
Notifications
You must be signed in to change notification settings - Fork 14
/
updateWeb.py
109 lines (79 loc) · 3.09 KB
/
updateWeb.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# update websites with Radiation Data
# configuration in updateWeb.conf
import traceback
import sys
try:
import updateWebConfigLocal as updateWebConfig
print("updateWebConfigLocal Found")
except:
import updateWebConfig
print ("using updateWebConfig")
import requests
import config
try:
import SafecastPy
except:
print("SafecastPy missing. run: sudo pip3 install SafecastPy ")
sys.exit(1)
import datetime
safecast = SafecastPy.SafecastPy(
api_key=updateWebConfig.SAFECASTAPI)
def sendCommandToIP(myIP, myCommand):
myURL = 'http://'+myIP+'/'+myCommand
try:
if (config.SWDEBUG):
print("myURL=", myURL)
req = requests.get(myURL,timeout=5)
returnReq = req
except Exception:
traceback.print_exc()
return
return returnReq
def update_SafeCast(CPM, uSVh):
if (updateWebConfig.SAFECASTAPI != ""):
print("Updating SafeCast")
try:
measurement = safecast.add_measurement(json={
'latitude': updateWebConfig.RADLATITUDE,
'longitude': updateWebConfig.RADLONGITUDE,
'value': CPM,
'unit': SafecastPy.UNIT_CPM,
'captured_at': datetime.datetime.utcnow().isoformat() + '+00:00',
'device_id': 90,
'location_name': updateWebConfig.RADLOCATIONNAME,
'height': updateWebConfig.RADHEIGHTINMETERS
})
print("CPM measurement= ", measurement)
print('New CPM measurement id: {0}'.format(measurement['id']))
measurement = safecast.add_measurement(json={
'latitude': updateWebConfig.RADLATITUDE,
'longitude': updateWebConfig.RADLONGITUDE,
'value': uSVh,
'unit': SafecastPy.UNIT_USV,
'captured_at': datetime.datetime.utcnow().isoformat() + '+00:00',
'device_id': 90,
'location_name': updateWebConfig.RADLOCATIONNAME,
'height': updateWebConfig.RADHEIGHTINMETERS
})
print("measurement= ", measurement)
print('New measurement id: {0}'.format(measurement['id']))
except Exception:
traceback.print_exc()
return
pass
def update_NETC(CPM):
pass
def update_RadMon(CPM):
if (updateWebConfig.RADMONUSER != ""):
myCommand = "radmon.php?function=submit&user="+updateWebConfig.RADMONUSER +"&password="+updateWebConfig.RADMONPASSWORD+"&value="+str(CPM)+ "&unit=CPM"
print("myCommand=", myCommand)
response = sendCommandToIP(updateWebConfig.RADMONIPADDRESS, myCommand)
print("response=", response)
pass
def update_GMCMap(CPM, uSVh):
if (updateWebConfig.GMCMAPUSERACCOUNTID != ""):
myCommand = "log2.asp?AID="+updateWebConfig.GMCMAPUSERACCOUNTID+"&GID="+updateWebConfig.GMCMAPGEIGERCOUNTERID+"&CPM="+str(CPM)+"&uSV="+str(uSVh)
print("myCommand=", myCommand)
response = sendCommandToIP(updateWebConfig.GMCMAPIPADDRESS, myCommand)
print("response=", response)
pass