mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
Lukazlim: Replace dependency requests
with httpx
(#12744)
* Replace dependency `requests` with `httpx` Fixes #12742 Signed-off-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> * updating DIRECTORY.md * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> Co-authored-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> Co-authored-by: cclauss <cclauss@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,4 +1,11 @@
|
||||
import requests
|
||||
# /// script
|
||||
# requires-python = ">=3.13"
|
||||
# dependencies = [
|
||||
# "httpx",
|
||||
# ]
|
||||
# ///
|
||||
|
||||
import httpx
|
||||
|
||||
# Put your API key(s) here
|
||||
OPENWEATHERMAP_API_KEY = ""
|
||||
@ -19,13 +26,13 @@ def current_weather(location: str) -> list[dict]:
|
||||
weather_data = []
|
||||
if OPENWEATHERMAP_API_KEY:
|
||||
params_openweathermap = {"q": location, "appid": OPENWEATHERMAP_API_KEY}
|
||||
response_openweathermap = requests.get(
|
||||
response_openweathermap = httpx.get(
|
||||
OPENWEATHERMAP_URL_BASE, params=params_openweathermap, timeout=10
|
||||
)
|
||||
weather_data.append({"OpenWeatherMap": response_openweathermap.json()})
|
||||
if WEATHERSTACK_API_KEY:
|
||||
params_weatherstack = {"query": location, "access_key": WEATHERSTACK_API_KEY}
|
||||
response_weatherstack = requests.get(
|
||||
response_weatherstack = httpx.get(
|
||||
WEATHERSTACK_URL_BASE, params=params_weatherstack, timeout=10
|
||||
)
|
||||
weather_data.append({"Weatherstack": response_weatherstack.json()})
|
||||
|
Reference in New Issue
Block a user