reiiiii 2023. 5. 7. 16:26

https://openweathermap.org/

 

Сurrent weather and forecast - OpenWeatherMap

Access current weather data for any location on Earth including over 200,000 cities! The data is frequently updated based on the global and local weather models, satellites, radars and a vast network of weather stations. how to obtain APIs (subscriptions w

openweathermap.org

*멋사 0506스터디

*파이썬으로 실습함

import requests
import json
city = "Seoul"
API = "1baf9456d798899fd883c214178e51ee"

api=f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={API}&units=metric"

result = requests.get(api)
print(result.text)

data = json.loads(result.text)
print(data)
print("-"*40)

print(data["name"],"의 날씨입니다.")
print("날씨는",data["weather"][0]["description"],"입니다.")
print("현재온도는",data["main"]["temp"],"입니다.")
print("하지만 체감",data["main"]["feels_like"],"입니다.")
print("최저 기온은",data["main"]["temp_min"],"입니다.")
print("최고 기온은",data["main"]["temp_max"],"입니다.")
print("습도는",data["main"]["humidity"],"입니다.")
print("기압은",data["main"]["pressure"],"입니다.")
print("풍향은",data["wind"]["deg"],"입니다.")
print("풍속은",data["wind"]["speed"],"입니다.")

[출력화면]