File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 1- # TODO - RELOCATE ALL API CALLING TO THIS MODULE
2- # TODO - ENSURE API IS WORKING OR ELSE FIND ONE THAT IS
1+ import requests
2+ 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 ])
You can’t perform that action at this time.
0 commit comments