From dd3f3e3290aa5cd3b8b24deafc30462973f16478 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 30 May 2020 18:05:59 +0200 Subject: [PATCH 1/3] current_weather, weather_forecast, weather_onecall --- web_programming/current_weather.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/web_programming/current_weather.py b/web_programming/current_weather.py index a35fff2d4615..a054aa29b8a7 100644 --- a/web_programming/current_weather.py +++ b/web_programming/current_weather.py @@ -1,16 +1,27 @@ -from pprint import pprint - import requests APPID = "" # <-- Put your OpenWeatherMap appid here! -URL_BASE = "http://api.openweathermap.org/data/2.5/weather" +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 current_weather(location: str = "Chicago", appid: str = APPID) -> dict: - return requests.get(URL_BASE, params={"appid": appid, "q": location}).json() +def weather_forecast(q: str = "New York", 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: From 70e5620bec537802d1b43bf1fc1693969c587b21 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 30 May 2020 16:06:22 +0000 Subject: [PATCH 2/3] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 935755de6ff5..78095b2645a4 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -641,6 +641,7 @@ ## Web Programming * [Crawl Google Results](https://github.com/TheAlgorithms/Python/blob/master/web_programming/crawl_google_results.py) * [Current Stock Price](https://github.com/TheAlgorithms/Python/blob/master/web_programming/current_stock_price.py) + * [Current Weather](https://github.com/TheAlgorithms/Python/blob/master/web_programming/current_weather.py) * [Emails From Url](https://github.com/TheAlgorithms/Python/blob/master/web_programming/emails_from_url.py) * [Fetch Bbc News](https://github.com/TheAlgorithms/Python/blob/master/web_programming/fetch_bbc_news.py) * [Fetch Github Info](https://github.com/TheAlgorithms/Python/blob/master/web_programming/fetch_github_info.py) From 95a1f226ba01d4e47915e63b8b9287b98ecf647c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 30 May 2020 18:29:02 +0200 Subject: [PATCH 3/3] weather_forecast("Kolkata, India") --- web_programming/current_weather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_programming/current_weather.py b/web_programming/current_weather.py index a054aa29b8a7..e043b438473f 100644 --- a/web_programming/current_weather.py +++ b/web_programming/current_weather.py @@ -9,7 +9,7 @@ def current_weather(q: str = "Chicago", appid: str = APPID) -> dict: return requests.get(URL_BASE + "weather", params=locals()).json() -def weather_forecast(q: str = "New York", appid: str = APPID) -> dict: +def weather_forecast(q: str = "Kolkata, India", appid: str = APPID) -> dict: """https://openweathermap.org/forecast5""" return requests.get(URL_BASE + "forecast", params=locals()).json()