Skip to content

Commit fa358d6

Browse files
cclaussgithub-actions
and
github-actions
authored
current_weather, weather_forecast, weather_onecall (TheAlgorithms#2048)
* current_weather, weather_forecast, weather_onecall * updating DIRECTORY.md * weather_forecast("Kolkata, India") Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent f8bfd02 commit fa358d6

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

DIRECTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@
641641
## Web Programming
642642
* [Crawl Google Results](https://github.com/TheAlgorithms/Python/blob/master/web_programming/crawl_google_results.py)
643643
* [Current Stock Price](https://github.com/TheAlgorithms/Python/blob/master/web_programming/current_stock_price.py)
644+
* [Current Weather](https://github.com/TheAlgorithms/Python/blob/master/web_programming/current_weather.py)
644645
* [Emails From Url](https://github.com/TheAlgorithms/Python/blob/master/web_programming/emails_from_url.py)
645646
* [Fetch Bbc News](https://github.com/TheAlgorithms/Python/blob/master/web_programming/fetch_bbc_news.py)
646647
* [Fetch Github Info](https://github.com/TheAlgorithms/Python/blob/master/web_programming/fetch_github_info.py)

web_programming/current_weather.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
from pprint import pprint
2-
31
import requests
42

53
APPID = "" # <-- Put your OpenWeatherMap appid here!
6-
URL_BASE = "http://api.openweathermap.org/data/2.5/weather"
4+
URL_BASE = "http://api.openweathermap.org/data/2.5/"
5+
6+
7+
def current_weather(q: str = "Chicago", appid: str = APPID) -> dict:
8+
"""https://openweathermap.org/api"""
9+
return requests.get(URL_BASE + "weather", params=locals()).json()
710

811

9-
def current_weather(location: str = "Chicago", appid: str = APPID) -> dict:
10-
return requests.get(URL_BASE, params={"appid": appid, "q": location}).json()
12+
def weather_forecast(q: str = "Kolkata, India", appid: str = APPID) -> dict:
13+
"""https://openweathermap.org/forecast5"""
14+
return requests.get(URL_BASE + "forecast", params=locals()).json()
15+
16+
17+
def weather_onecall(lat: float = 55.68, lon: float = 12.57, appid: str = APPID) -> dict:
18+
"""https://openweathermap.org/api/one-call-api"""
19+
return requests.get(URL_BASE + "onecall", params=locals()).json()
1120

1221

1322
if __name__ == "__main__":
23+
from pprint import pprint
24+
1425
while True:
1526
location = input("Enter a location:").strip()
1627
if location:

0 commit comments

Comments
 (0)