mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
fa358d614a
* current_weather, weather_forecast, weather_onecall * updating DIRECTORY.md * weather_forecast("Kolkata, India") Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
31 lines
947 B
Python
31 lines
947 B
Python
import requests
|
|
|
|
APPID = "" # <-- Put your OpenWeatherMap appid here!
|
|
URL_BASE = "http://api.openweathermap.org/data/2.5/"
|
|
|
|
|
|
def current_weather(q: str = "Chicago", appid: str = APPID) -> dict:
|
|
"""https://openweathermap.org/api"""
|
|
return requests.get(URL_BASE + "weather", params=locals()).json()
|
|
|
|
|
|
def weather_forecast(q: str = "Kolkata, India", appid: str = APPID) -> dict:
|
|
"""https://openweathermap.org/forecast5"""
|
|
return requests.get(URL_BASE + "forecast", params=locals()).json()
|
|
|
|
|
|
def weather_onecall(lat: float = 55.68, lon: float = 12.57, appid: str = APPID) -> dict:
|
|
"""https://openweathermap.org/api/one-call-api"""
|
|
return requests.get(URL_BASE + "onecall", params=locals()).json()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from pprint import pprint
|
|
|
|
while True:
|
|
location = input("Enter a location:").strip()
|
|
if location:
|
|
pprint(current_weather(location))
|
|
else:
|
|
break
|