-
Notifications
You must be signed in to change notification settings - Fork 5
/
weather_api.py
36 lines (25 loc) · 1.08 KB
/
weather_api.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
from weather import Weather, Unit
import pandas as pd
def daily(location):
weather = Weather(unit=Unit.CELSIUS)
location = weather.lookup_by_location(location)
forecasts = location.forecast
atmosphere = location.atmosphere
text_forecast = 'Today, the weather is %s. The temperature varies from %d Cel to %d Cel. Humidity is %d'%(forecasts[0].text, int(forecasts[0].low), int(forecasts[0].high), int(atmosphere['humidity']))
return str(text_forecast)
def weekly(location):
weather = Weather(unit=Unit.CELSIUS)
location = weather.lookup_by_location(location)
forecasts = location.forecast
date = []
text = []
high = []
low = []
for forecast in forecasts:
date.append(forecast.date)
text.append(forecast.text)
high.append(forecast.high)
low.append(forecast.low)
weather_table = pd.concat([pd.Series(date),pd.Series(text),pd.Series(high),pd.Series(low)],axis =1,ignore_index = True)
weather_table.columns = ['Date', 'Condition', 'High Temperature', 'Low Temperature']
return weather_table[:7]