-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
50 lines (38 loc) · 1.11 KB
/
test.py
File metadata and controls
50 lines (38 loc) · 1.11 KB
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
42
43
44
45
46
47
48
49
50
# data.py
# GETS THE USER'S LOCATION AND WEATHER
from geopy.geocoders import Nominatim
import geocoder
import requests
# GET LATITUDE AND LONGITUDE
g = geocoder.ip('me')
latlng = g.latlng
lat = latlng[0]
lon = latlng[1]
# GET CITY
geolocator = Nominatim(user_agent="geoapiExercises")
location = geolocator.reverse(f'{lat},{lon}')
address = location.raw['address']
city = address['city']
# GET WEATHER FROM RapidAPI
url = "https://community-open-weather-map.p.rapidapi.com/find"
querystring = {
"q": city,
"units":"metric"
}
headers = {
'x-rapidapi-key': "dc0c7bf93cmsh677e885936c4596p117065jsnc7cc0f3f16c0",
'x-rapidapi-host': "community-open-weather-map.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring)
# DATA
data = response.json()['list'][0]
"""
# Weather in metric system
weather = data['main']['temp']
feels_like = data['main']['feels_like']
max = data['main']['temp_max']
min = data['main']['temp_min']
city = data['name']
description = data['weather'][0]['description']
icon = data['weather'][0]['icon']
"""