forked from wasmerio/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrencies.py
More file actions
46 lines (35 loc) · 1.54 KB
/
Copy pathcurrencies.py
File metadata and controls
46 lines (35 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from api_handler import get_exchange_data
def get_supported_currencies(rates):
"""
Return a list of supported currency codes from the rates dictionary.
Args:
rates (dict): Dictionary of currency codes and their exchange rates.
Returns:
list: List of supported currency codes (e.g., ['USD', 'EUR']).
"""
return list(rates.keys())
def is_valid_currency(currency_code, rates):
"""
Check if the given currency code is valid and supported.
Args:
currency_code (str): Currency code to validate (e.g., 'USD').
rates (dict): Dictionary of available exchange rates.
Returns:
bool: True if the currency code exists in the rates, False otherwise.
"""
return currency_code.upper() in rates
# --- DEBUG / MANUAL TEST SECTION ---
# This section runs only when you run this file directly (not when imported elsewhere)
if __name__ == "__main__":
# Fetch live exchange data from the API
exchange_data = get_exchange_data()
# Print the first 5 currencies for quick inspection
print("Sample of live rates from API:")
print(list(exchange_data["rates"].items())[:5])
# Sample rates dictionary for local testing
rates_example = {"USD": 1.12, "EUR": 1.0, "GBP": 0.87}
# Print supported currencies
print("\nSupported currencies:", get_supported_currencies(rates_example))
# Check a few currency codes
print("Is 'usd' valid?", is_valid_currency("usd", rates_example)) # True
print("Is 'AUD' valid?", is_valid_currency("AUD", rates_example)) # False