-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.py
41 lines (31 loc) · 1.16 KB
/
weather.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
from pyowm import OWM
owm = OWM("6c84507cbe013046861cd673e1a59a75")
def get_forecasts(lat, lon):
observation = owm.three_hours_forecast_at_coords(lat, lon)
forecasts = observation.get_forecast()
location = forecasts.get_location()
loc_name = location.get_name()
loc_lat = location.get_lat()
loc_lon = location.get_lon()
results = []
for forecast in forecasts:
time = forecast.get_reference_time('iso')
status = forecast.get_status()
detailed = forecast.get_detailed_status()
temperature = forecast.get_temperature('celsius')
temp = temperature.get("temp")
temp_min = temperature.get("temp_min")
temp_max = temperature.get("temp_max")
results.append("""
Location : {} Lat : {} Lon {}
Time : {}
Status : {}
Detailed : {}
Temperature : {}
Min Temperature : {}
Max Temperature : {}
""".format(loc_name, loc_lat, loc_lon, time,
status, detailed, temp, temp_min, temp_max))
return "".join(results[:10])
if __name__ == "__main__":
print(get_forecasts(-1.2, 36))