We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 08d29b9 + c6f47c2 commit 62fe11aCopy full SHA for 62fe11a
1 file changed
Currency Script/src/api_handler.py
@@ -1,2 +1,18 @@
1
-# TODO - RELOCATE ALL API CALLING TO THIS MODULE
2
-# TODO - ENSURE API IS WORKING OR ELSE FIND ONE THAT IS
+import requests
+import json
3
+
4
+def get_exchange_data(api_url: str = "https://theratesapi.com/api/latest/") -> dict:
5
+ """Fetch latest exchange data from the API."""
6
+ response = requests.get(api_url)
7
+ if response.status_code != 200:
8
+ raise Exception(f"API request failed with status {response.status_code}")
9
10
+ data = response.json()
11
+ return data # This includes 'base', 'date', and 'rates'
12
13
+# NOTE - for logging & debugging
14
+if __name__ == "__main__":
15
+ exchange_data = get_exchange_data()
16
+ print("Base currency:", exchange_data["base"])
17
+ print("Date:", exchange_data["date"])
18
+ print("Rates:", list(exchange_data["rates"].items())[:5])
0 commit comments