This repository has been archived by the owner on Oct 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weatherData.py
executable file
·48 lines (40 loc) · 1.62 KB
/
weatherData.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
#!/usr/bin/env /usr/local/bin/python3.9
import json
import os
import subprocess
import sys
homedir = sys.path[0]
filename = 'netatmo.json'
netatmo = os.path.join(homedir, filename);
if not os.path.exists(netatmo):
print("File doesnt exists, downloading")
cmd = ['python3.9', 'getWeather.py']
subprocess.Popen(cmd).wait()
with open(netatmo, 'r') as json_file:
data = json.load(json_file)
weatherList = {}
temp = { 'temperature': data['body']['devices'][0]['modules'][0]['dashboard_data']['Temperature'] }
humidity = { 'humidity': data['body']['devices'][0]['modules'][0]['dashboard_data']['Humidity'] }
temp_trend = { 'temp_trend': data['body']['devices'][0]['modules'][0]['dashboard_data']['temp_trend'] }
pressure = { 'pressure': data['body']['devices'][0]['dashboard_data']['Pressure'] }
pressure_trend = { 'pressure_trend': data['body']['devices'][0]['dashboard_data']['pressure_trend'] }
co2 = { 'co2': data['body']['devices'][0]['dashboard_data']['CO2'] }
weatherList.update(temp)
weatherList.update(humidity)
weatherList.update(temp_trend)
weatherList.update(pressure)
weatherList.update(pressure_trend)
weatherList.update(co2)
try:
weatherList.update({'min_temp': data['body']['devices'][0]['modules'][0]['dashboard_data']['min_temp'] })
except KeyError:
print("No min temp data yet")
try:
weatherList.update({'max_temp': data['body']['devices'][0]['modules'][0]['dashboard_data']['max_temp'] })
except KeyError:
print("No max temp data yet")
try:
weatherList.update({'rain': data['body']['devices'][0]['modules'][1]['dashboard_data']['Rain'] })
except KeyError:
print("No rain data yet")
print(weatherList)