There was an error while loading. Please reload this page.
1 parent ad13a49 commit a3aff66Copy full SHA for a3aff66
1 file changed
web_programming/crypto_price.py
@@ -5,11 +5,11 @@
5
# /// script
6
# requires-python = ">=3.10"
7
# dependencies = [
8
-# "httpx",
+# "httpx2",
9
# ]
10
# ///
11
12
-import httpx
+import httpx2
13
14
COINGECKO_URL = (
15
"https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"
@@ -18,10 +18,7 @@
18
19
def get_eth_price_usd() -> float:
20
"""Fetch the current ETH price in USD."""
21
- response = httpx.get(COINGECKO_URL, timeout=10)
22
- response.raise_for_status()
23
- data = response.json()
24
- return data["ethereum"]["usd"]
+ return httpx2.get(COINGECKO_URL, timeout=10).raise_for_status().json()["ethereum"]["usd"]
25
26
27
def eth_to_usd(eth_amount: float) -> float:
0 commit comments