-
Notifications
You must be signed in to change notification settings - Fork 3
/
model.py
29 lines (24 loc) · 1.13 KB
/
model.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
import requests
#class WeatherInfo:
def getWeather(city):
hourlyWeather = {}
weatherData = requests.get('http://api.openweathermap.org/data/2.5/forecast?q={}&APPID=225800a064f12ac6d7fbaadf83ce753f'.format(city))
weatherData = weatherData.json()
for x in range(8):
dateTime = weatherData['list'][x]['dt_txt']
timeArr = dateTime.rsplit(" ")
date = timeArr[0]
time = timeArr[1]
if (time == "12:00:00"):
hourlyWeather["Temperature"] = round((weatherData['list'][x]['main']['temp'] - 273.15), 1)
hourlyWeather["Weather"] = weatherData['list'][x]['weather'][0]['main']
hourlyWeather["Weather Details"] = weatherData['list'][x]['weather'][0]['description']
hourlyWeather["Wind Speed"] = round((weatherData['list'][x]['wind']['speed']),2)
hourlyWeather["Date"] = date
return hourlyWeather
def check_status_code(city):
response = requests.get('http://api.openweathermap.org/data/2.5/forecast?q={}&APPID=225800a064f12ac6d7fbaadf83ce753f'.format(city))
if int(response.status_code) != 200:
return False
else:
return True