Q:

Create a Python project to display the weather forecast of a given city

0

Create a Python project to display the weather forecast of a given city.

Use the Weather API of openweathermap.org
To create a A/c go to
https://home.openweathermap.org/users/sign_up

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#Source: https://bit.ly/2MjeQ6z
import requests
APPID = "**************************"  # <-- Put your OpenWeatherMap appid here!
URL_BASE = "http://api.openweathermap.org/data/2.5/"
def current_weather(q: str = "", appid: str = APPID) -> dict:
    """https://openweathermap.org/api"""
    return requests.get(URL_BASE + "weather", params=locals()).json()
def weather_forecast(q: str = "", 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("Input a location: ").strip()
        if location:
            pprint(current_weather(location))
        else:
            break

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now