-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather_go.py
36 lines (24 loc) · 805 Bytes
/
weather_go.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
import requests
def weather_data(query):
res = requests.get(
'http://api.openweathermap.org/data/2.5/weather?' + query + '&APPID=0142515b87702fb26174239fb8b60b09&units=metric')
return res.json()
def temperature(result):
temp = ("{}°C".format(result['main']['temp']))
return temp
def wind_speed(result):
speed = result['wind']['speed']
return str(speed) + " meter per second"
def Description(result):
description = result['weather'][0]['description']
return description
def Weather(result):
weather = result['weather'][0]['main']
return weather
city = "islamabad"
query = 'q=' + city
w_data = weather_data(query)
city_temp = temperature(w_data)
city_wind_speed = wind_speed(w_data)
city_disc = Description(w_data)
city_weather = Weather(w_data)