-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweatherblock.py
executable file
·37 lines (28 loc) · 940 Bytes
/
weatherblock.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
#!/home/trst2284/.local/share/virtualenvs/noaablocks-nPJEcr8f/bin/python3
# TODO eventually we'll have a cli instead of this terrible script.
def main():
try:
forecast = get_hourly_forecast(*get_location())
temp, next_temp = get_current_temp(forecast)
except:
print("{'full_text': 'ERROR'}")
return
json_dict = {
'full_text': '{} {} {} degrees'.format(temp, '->', next_temp)
}
print(json.dumps(json_dict))
return
if __name__ == '__main__':
try:
import json
from noaablocks.weather import get_hourly_forecast, get_location, get_current_temp
main()
except Exception as e:
with open('/tmp/error.log', 'a') as f:
f.write('{}'.format(e))
try:
import sys
f.write('{}'.format(sys.executable))
except:
pass
print("{\"full_text\": \"ERROR\"}")