-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteleweather.py
38 lines (31 loc) · 1.21 KB
/
teleweather.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
import requests
def res(url):
""" To ping the website using the url for information"""
response = requests.get(url)
data = response.json()
return data
def location():
""" To find the location of the current user using his ip address"""
url = 'https://ipinfo.io/'
data = res(url)
city = data['city']
location = data['loc'].split(',')
latitude = location[0]
longitude = location[1]
return latitude,longitude
def get_weather():
""" To find the weather of that current location"""
lat,lon = location()
url = 'http://api.openweathermap.org/data/2.5/weather?lat={}&lon={}&appid=d5cba1979a99f72e6014b8127038248c&units=metric'.format(lat, lon)
table_data = ["temp", "humidity", "pressure", "wspeed", "wdegree", "longitude", "latitude", "desc", "city"]
data = res(url)
temp = data['main']['temp']
humidity= data['main']['humidity']
pressure = data['main']['pressure']
wspeed = data['wind']['speed']
wdegree = data['wind']['deg']
longitude = data['coord']['lon']
latitude = data['coord']['lat']
desc = data['weather'][0]['description']
city = data['name']
return temp, humidity, pressure, wspeed, wdegree, longitude, latitude, desc, city