-
Notifications
You must be signed in to change notification settings - Fork 0
/
alerts.py
97 lines (88 loc) · 4.21 KB
/
alerts.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
#alerts.py
from datetime import datetime
air_map_url = "http://maps.luftdaten.info/#13/"
AQI = [
{"aqi": "0-50", "apl": "Good",
"health_implications": "Air quality is considered satisfactory, and air pollution poses little or no risk",
"cautionary_statement" : "None"
},
{"aqi": "51-100", "apl": "Moderate",
"health_implications": "Air quality is acceptable; however, for some pollutants there may be a moderate health concern for a very small number of people who are unusually sensitive to air pollution.",
"cautionary_statement" : "Active children and adults, and people with respiratory disease, such as asthma, should limit prolonged outdoor exertion"
},
{"aqi": "101-150", "apl": "Unhealthy for Sensitive Groups",
"health_implications": "Members of sensitive groups may experience health effects. The general public is not likely to be affected.",
"cautionary_statement" : "Active children and adults, and people with respiratory disease, such as asthma, should limit prolonged outdoor exertion."
},
{"aqi": "151-200", "apl": "Unhealthy",
"health_implications": "Everyone may begin to experience health effects; members of sensitive groups may experience more serious health effects",
"cautionary_statement" : "Active children and adults, and people with respiratory disease, such as asthma, should avoid prolonged outdoor exertion; everyone else, especially children, should limit prolonged outdoor exertion"
},
{"aqi": "201-300", "apl": "Very Unhealthy",
"health_implications": "Health warnings of emergency conditions. The entire population is more likely to be affected.",
"cautionary_statement" : "Active children and adults, and people with respiratory disease, such as asthma, should avoid all outdoor exertion; everyone else, especially children, should limit outdoor exertion."
},
{"aqi": "300+", "apl": "Hazardous",
"health_implications": "Health alert: everyone may experience more serious health effects",
"cautionary_statement" : "Everyone should avoid all outdoor exertion"
},
]
def alert_message(p1, p2, sensor_id, location):
#get air pollutioin health message
if p2 < 50:
apl = AQI[0]['apl']
health_implications = AQI[0]['health_implications']
cautionary_statement = AQI[0]['cautionary_statement']
elif p2 >= 50 and p2 <= 100:
apl = AQI[1]['apl']
health_implications = AQI[1]['health_implications']
cautionary_statement = AQI[1]['cautionary_statement']
elif p2 >= 101 and p2 <= 150:
apl = AQI[2]['apl']
health_implications = AQI[2]['health_implications']
cautionary_statement = AQI[2]['cautionary_statement']
elif p2 >= 151 and p2 <= 200:
apl = AQI[3]['apl']
health_implications = AQI[3]['health_implications']
cautionary_statement = AQI[3]['cautionary_statement']
elif p2 >= 201 and p2 <= 300:
apl = AQI[4]['apl']
health_implications = AQI[4]['health_implications']
cautionary_statement = AQI[4]['cautionary_statement']
elif p2 > 300:
apl = AQI[5]['apl']
health_implications = AQI[5]['health_implications']
cautionary_statement = AQI[5]['cautionary_statement']
#read the html template
with open('/home/pi/scripts/air_check/templates/polluted_air.html', 'r') as templatefile:
message = templatefile.readlines()
#populate html template
message = "".join(message).format( apl = apl,
health_implications = health_implications,
cautionary_statement = cautionary_statement,
map_url = air_map_url + location.replace(",", "/"),
today = datetime.today().strftime("%Y-%m-%d %H:%M"),
p1 = p1,
p2 = p2,
stationid = sensor_id,
location = location,
)
return message
def ok_message(ok_value, p1, p2, last_p1, last_p2,
sensor_id, last_alert_date, location):
#read the html template
with open('/home/pi/scripts/air_check/templates/clear_air.html', 'r') as templatefile:
message = templatefile.readlines()
#populate the html template
message = "".join(message).format(map_url = air_map_url + location.replace(",", "/"),
ok_value = ok_value,
today = datetime.today().strftime("%Y-%m-%d %H:%M"),
p1 = p1,
p2 = p2,
stationid = sensor_id,
lastpolutiondate = last_alert_date,
last_p1 = last_p1,
last_p2 = last_p2,
location = location
)
return message