-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.py
executable file
Β·33 lines (30 loc) Β· 1.19 KB
/
map.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
import requests
from concurrent.futures import ThreadPoolExecutor
cities = [
{"name": "μμΈ", "lat": 37.5665, "lon": 126.9780},
{"name": "ν리", "lat": 48.8566, "lon": 2.3522},
{"name": "λ΄μ", "lat": 40.7128, "lon": -74.0060},
{"name": "리μ°λ°μλ€μ΄λ£¨", "lat": -22.9068, "lon": -43.1729},
{"name": "μΉ΄μ΄λ‘", "lat": 30.0444, "lon": 31.2357},
{"name": "μλλ", "lat": -33.8688, "lon": 151.2093}
]
# λΉλκΈ° μ²λ¦¬
executor = ThreadPoolExecutor()
# API νΈμΆ λΉλκΈ° μ²λ¦¬ ν¨μ
def get_weather(city):
lat = city['lat']
lon = city['lon']
api_key = '9ca3cf87495eab0ae69dd2cf8ee9ff94'
url = f'https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={api_key}&units=metric'
response = requests.get(url).json()
if 'weather' in response:
weather_description = response['weather'][0]['description']
else:
weather_description = 'λ μ¨ μ 보 μμ'
temperature = response.get('main', {}).get('temp', 'μ¨λ μ 보 μμ')
city_weather = {
'name': city['name'],
'weather': weather_description,
'temperature': temperature
}
return city_weather