Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Currency Script/src/api_handler.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# TODO - RELOCATE ALL API CALLING TO THIS MODULE
# TODO - ENSURE API IS WORKING OR ELSE FIND ONE THAT IS
import requests
import json

def get_exchange_data(api_url: str = "https://theratesapi.com/api/latest/") -> dict:
"""Fetch latest exchange data from the API."""
response = requests.get(api_url)
if response.status_code != 200:
raise Exception(f"API request failed with status {response.status_code}")

data = response.json()
return data # This includes 'base', 'date', and 'rates'

# NOTE - for logging & debugging
if __name__ == "__main__":
exchange_data = get_exchange_data()
print("Base currency:", exchange_data["base"])
print("Date:", exchange_data["date"])
print("Rates:", list(exchange_data["rates"].items())[:5])