forked from charlesmadere/CynanBotCommon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweatherReport.py
147 lines (108 loc) · 5.71 KB
/
weatherReport.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import locale
from typing import List
import CynanBotCommon.utils as utils
class WeatherReport():
def __init__(
self,
airQuality: int,
humidity: int,
pressure: int,
temperature: float,
tomorrowsHighTemperature: float,
tomorrowsLowTemperature: float,
alerts: List[str],
conditions: List[str],
tomorrowsConditions: List[str]
):
if not utils.isValidNum(humidity):
raise ValueError(f'humidity argument is malformed: \"{humidity}\"')
elif not utils.isValidNum(pressure):
raise ValueError(f'pressure argument is malformed: \"{pressure}\"')
elif not utils.isValidNum(temperature):
raise ValueError(f'temperature argument is malformed: \"{temperature}\"')
elif not utils.isValidNum(tomorrowsHighTemperature):
raise ValueError(f'tomorrowsHighTemperature argument is malformed: \"{tomorrowsHighTemperature}\"')
elif not utils.isValidNum(tomorrowsLowTemperature):
raise ValueError(f'tomorrowsLowTemperature argument is malformed: \"{tomorrowsLowTemperature}\"')
self.__airQuality = airQuality
self.__humidity = humidity
self.__pressure = pressure
self.__temperature = temperature
self.__tomorrowsHighTemperature = tomorrowsHighTemperature
self.__tomorrowsLowTemperature = tomorrowsLowTemperature
self.__alerts = alerts
self.__conditions = conditions
self.__tomorrowsConditions = tomorrowsConditions
def __cToF(self, celsius: float) -> float:
return (celsius * (9 / 5)) + 32
def getAirQuality(self) -> int:
return self.__airQuality
def getAirQualityStr(self) -> str:
return locale.format_string("%d", self.getAirQuality(), grouping = True)
def getAlerts(self) -> List[str]:
return self.__alerts
def getConditions(self) -> List[str]:
return self.__conditions
def getHumidity(self) -> int:
return self.__humidity
def getPressure(self) -> int:
return self.__pressure
def getPressureStr(self) -> str:
return locale.format_string("%d", self.getPressure(), grouping = True)
def getTemperature(self):
return int(round(self.__temperature))
def getTemperatureStr(self):
return locale.format_string("%d", self.getTemperature(), grouping = True)
def getTemperatureImperial(self):
return int(round(self.__cToF(self.__temperature)))
def getTemperatureImperialStr(self):
return locale.format_string("%d", self.getTemperatureImperial(), grouping = True)
def getTomorrowsConditions(self) -> List[str]:
return self.__tomorrowsConditions
def getTomorrowsLowTemperature(self) -> int:
return int(round(self.__tomorrowsLowTemperature))
def getTomorrowsLowTemperatureStr(self) -> str:
return locale.format_string("%d", self.getTomorrowsLowTemperature(), grouping = True)
def getTomorrowsLowTemperatureImperial(self) -> int:
return int(round(self.__cToF(self.__tomorrowsLowTemperature)))
def getTomorrowsLowTemperatureImperialStr(self) -> str:
return locale.format_string("%d", self.getTomorrowsLowTemperatureImperial(), grouping = True)
def getTomorrowsHighTemperature(self) -> int:
return int(round(self.__tomorrowsHighTemperature))
def getTomorrowsHighTemperatureStr(self) -> str:
return locale.format_string("%d", self.getTomorrowsHighTemperature(), grouping = True)
def getTomorrowsHighTemperatureImperial(self) -> int:
return int(round(self.__cToF(self.__tomorrowsHighTemperature)))
def getTomorrowsHighTemperatureImperialStr(self) -> str:
return locale.format_string("%d", self.getTomorrowsHighTemperatureImperial(), grouping = True)
def hasAirQuality(self) -> bool:
return utils.isValidNum(self.__airQuality)
def hasAlerts(self) -> bool:
return utils.hasItems(self.__alerts)
def hasConditions(self) -> bool:
return utils.hasItems(self.__conditions)
def hasTomorrowsConditions(self) -> bool:
return utils.hasItems(self.__tomorrowsConditions)
def toStr(self, delimiter: str = ', ') -> str:
if delimiter is None:
raise ValueError(f'delimiter argument is malformed: \"{delimiter}\"')
temperature = f'🌡 Temperature is {self.getTemperatureStr()}°C ({self.getTemperatureImperialStr()}°F), '
humidity = f'humidity is {self.getHumidity()}%, '
airQuality = ''
if self.hasAirQuality():
airQuality = f'air quality is {self.getAirQualityStr()}, '
pressure = f'and pressure is {self.getPressureStr()} hPa. '
conditions = ''
if self.hasConditions():
conditionsJoin = delimiter.join(self.getConditions())
conditions = f'Current conditions: {conditionsJoin}. '
tomorrowsTemps = f'Tomorrow has a low of {self.getTomorrowsLowTemperatureStr()}°C ({self.getTomorrowsLowTemperatureImperialStr()}°F) and a high of {self.getTomorrowsHighTemperatureStr()}°C ({self.getTomorrowsHighTemperatureImperialStr()}°F). '
tomorrowsConditions = ''
if self.hasTomorrowsConditions():
tomorrowsConditionsJoin = delimiter.join(self.getTomorrowsConditions())
tomorrowsConditions = f'Tomorrow\'s conditions: {tomorrowsConditionsJoin}. '
alerts = ''
if self.hasAlerts():
alertsJoin = ' '.join(self.getAlerts())
alerts = f'🚨 {alertsJoin}'
return f'{temperature}{humidity}{airQuality}{pressure}{conditions}{tomorrowsTemps}{tomorrowsConditions}{alerts}'