mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
current_weather, weather_forecast, weather_onecall (#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>
This commit is contained in:
parent
f8bfd0244d
commit
fa358d614a
@ -641,6 +641,7 @@
|
|||||||
## Web Programming
|
## Web Programming
|
||||||
* [Crawl Google Results](https://github.com/TheAlgorithms/Python/blob/master/web_programming/crawl_google_results.py)
|
* [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 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)
|
* [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 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)
|
* [Fetch Github Info](https://github.com/TheAlgorithms/Python/blob/master/web_programming/fetch_github_info.py)
|
||||||
|
@ -1,16 +1,27 @@
|
|||||||
from pprint import pprint
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
APPID = "" # <-- Put your OpenWeatherMap appid here!
|
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(location: str = "Chicago", appid: str = APPID) -> dict:
|
def current_weather(q: str = "Chicago", appid: str = APPID) -> dict:
|
||||||
return requests.get(URL_BASE, params={"appid": appid, "q": location}).json()
|
"""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__":
|
if __name__ == "__main__":
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
location = input("Enter a location:").strip()
|
location = input("Enter a location:").strip()
|
||||||
if location:
|
if location:
|
||||||
|
Loading…
Reference in New Issue
Block a user