-
Notifications
You must be signed in to change notification settings - Fork 1
/
ZoneData.py
51 lines (40 loc) · 1.68 KB
/
ZoneData.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
from datetime import datetime
from pyowm.commons.exceptions import InvalidSSLCertificateError
from pytz import timezone
import Constants
from ZoneInfo import ZoneInfo
class ZoneData:
def __init__(self, zone: ZoneInfo):
self.zone = zone
self.datetime_data = None
self.zone_code = ""
self.condition = "clear_sky"
self.celsius = ""
self.fahrenheit = ""
def update_times(self):
data = timezone(self.zone.zone)
self.datetime_data = datetime.now(data)
self.zone_code = self.datetime_data.strftime(Constants.ZONE_CODE_FORMAT)
def update_weather(self):
try:
weather = Constants.API_INSTANCE.weather_at_place(self.zone.weather_name).weather
self.celsius = str(weather.temperature('celsius')['temp'])
self.fahrenheit = str(weather.temperature('fahrenheit')['temp'])
self.condition = weather.status.lower()
if self.condition == "smoke"\
or self.condition == "haze"\
or self.condition == "dust"\
or self.condition == "fog"\
or self.condition == "sand"\
or self.condition == "ash"\
or self.condition == "squall":
self.condition = "mist"
if self.condition != "tornado" and weather.weather_icon_name.endswith("n"):
self.condition += "_night"
except InvalidSSLCertificateError:
if self.condition == "":
self.condition = "clear"
if self.celsius == "":
self.celsius = "?"
if self.fahrenheit == "":
self.fahrenheit = "?"