-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weather_Domain.py
46 lines (36 loc) · 1.48 KB
/
Weather_Domain.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
from DomainMaster import DomainMaster
import pyowm
import json
### SOURCES_
### OpenWeatherMap API : http://openweathermap.org/price#weather
### PyOWM Wrapper : https://github.com/csparpa/pyowm
### PyOWM Examples : https://github.com/csparpa/pyowm/blob/master/pyowm/docs/usage-examples.md
class Weather_Domain(DomainMaster):
def __init__(self, domainDIR, d, PN):
DomainMaster.__init__(self, domainDIR)
self.set_pronoun_and_domain(PN, d)
## Enter API key.
self.owm = pyowm.OWM('b29d29ef62921e78d4eae126872beec0')
## Retrieve weather observation data at location.
self.refresh_data()
##### ##### ##### ##### #####
##### ##### ##### ##### ##### OBSERVATION RETRIEVAL
##### ##### ##### ##### #####
### Updates most recently available data.
def refresh_data(self):
self.observation = self.owm.weather_at_place(self.get_pronoun())
self.weather = self.observation.get_weather()
## Update value dictionary.
self.set_value_dict(self.get_domain())
### Retrieves specified weather data given a type term.
def get_data_value(self, term):
## Check against available terms.
if term == "temperature":
val = self.weather.get_temperature('fahrenheit')['temp']
elif term == "humidity":
val = self.weather.get_humidity()
elif term == "wind speed":
val = self.weather.get_wind()['speed']
else:
return ("")
return (val)