currency-convert 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.3
2
+ Name: currency-convert
3
+ Version: 0.1.0
4
+ Summary: A simple library to convert an amount from one currency to another with rates updated daily. Powered by the Exchange API created by Fawaz Ahmed https://github.com/fawazahmed0/exchange-api
5
+ Author: Faisal
6
+ Author-email: Faisal <faisal@nihongoproject.com>
7
+ Requires-Dist: requests>=2.34.2
8
+ Requires-Python: >=3.14
9
+ Description-Content-Type: text/markdown
10
+
11
+ # Currency Converter Script
12
+
13
+ A lightweight Python tool that performs currency conversions using daily updated exchange rates. It fetches data from the open-source currency API developed by Fawaz Ahmed via the jsDelivr CDN.
14
+
15
+ **Financial Disclaimer:** This script uses daily cached exchange rates. It does not update in real-time and is not suitable for live financial trading or transactional environments.
16
+
17
+ ---
18
+
19
+ ## Features
20
+
21
+ * **Daily Rates:** Automatically fetches exchange rates matching your system's current date.
22
+ * **Format Ready:** Outputs currency values as clean, comma-separated strings rounded to 2 decimal places.
23
+ * **Error Handling:** Built-in protection against invalid or unavailable currency codes.
24
+ * **Case Insensitive:** Accepts both uppercase and lowercase currency codes (e.g., `CAD`, `cad`, `Cad`).
25
+
26
+ ---
27
+
28
+ ## 🛠️ Prerequisites & Tech Stack
29
+
30
+ * **Language:** Python 3.12 or later
31
+ * **Libraries:** `requests` (external HTTP library)
32
+
33
+ ### Install Dependencies
34
+
35
+ Before running the script, ensure you have the `requests` library installed:
36
+
37
+ ```bash
38
+ pip install requests
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Usage & API Reference
44
+
45
+ ### `current_rates(amount, input_currency, output_currency)`
46
+
47
+ Fetches the exchange rate for the current date and returns a formatted conversion string.
48
+
49
+ #### Parameters
50
+ * **`amount`** (`float` | `int`): The numerical value of the currency you want to convert.
51
+ * **`input_currency`** (`str`): The 3-letter ISO code for the base currency (e.g., `"cad"`).
52
+ * **`output_currency`** (`str`): The 3-letter ISO code for the target currency (e.g., `"jpy"`).
53
+
54
+ #### Return Value
55
+ * Returns a formatted `str` representing the converted amount (e.g., `"10,450.50"`), or an error message string (`"Currency not available"`).
56
+
57
+ ---
58
+
59
+ ## Quickstart Examples
60
+
61
+ You can import and run the function directly in your Python workflow:
62
+
63
+ ```python
64
+ # Example 1: Converting a whole number (100 CAD to JPY)
65
+ result_1 = current_rates(100, "cad", "jpy")
66
+ # Output: Prints and returns the converted formatted string
67
+
68
+ # Example 2: Converting a precise decimal number (540.65 CAD to JPY)
69
+ result_2 = current_rates(540.65, "CAD", "JPY")
70
+ ```
71
+
72
+ ---
73
+
74
+ ## Limitations & Data Sources
75
+
76
+ * **No Real-Time Tracking:** Rates are updated once per day by the data provider.
77
+ * **System Clock Dependency:** The script relies on `datetime.date.today()`. Ensure your system time is accurate to pull the correct daily file.
78
+ * **Data Provider:** Powered by the [@fawazahmed0/currency-api]([(https://github.com/fawazahmed0/exchange-api])).
@@ -0,0 +1,68 @@
1
+ # Currency Converter Script
2
+
3
+ A lightweight Python tool that performs currency conversions using daily updated exchange rates. It fetches data from the open-source currency API developed by Fawaz Ahmed via the jsDelivr CDN.
4
+
5
+ **Financial Disclaimer:** This script uses daily cached exchange rates. It does not update in real-time and is not suitable for live financial trading or transactional environments.
6
+
7
+ ---
8
+
9
+ ## Features
10
+
11
+ * **Daily Rates:** Automatically fetches exchange rates matching your system's current date.
12
+ * **Format Ready:** Outputs currency values as clean, comma-separated strings rounded to 2 decimal places.
13
+ * **Error Handling:** Built-in protection against invalid or unavailable currency codes.
14
+ * **Case Insensitive:** Accepts both uppercase and lowercase currency codes (e.g., `CAD`, `cad`, `Cad`).
15
+
16
+ ---
17
+
18
+ ## 🛠️ Prerequisites & Tech Stack
19
+
20
+ * **Language:** Python 3.12 or later
21
+ * **Libraries:** `requests` (external HTTP library)
22
+
23
+ ### Install Dependencies
24
+
25
+ Before running the script, ensure you have the `requests` library installed:
26
+
27
+ ```bash
28
+ pip install requests
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Usage & API Reference
34
+
35
+ ### `current_rates(amount, input_currency, output_currency)`
36
+
37
+ Fetches the exchange rate for the current date and returns a formatted conversion string.
38
+
39
+ #### Parameters
40
+ * **`amount`** (`float` | `int`): The numerical value of the currency you want to convert.
41
+ * **`input_currency`** (`str`): The 3-letter ISO code for the base currency (e.g., `"cad"`).
42
+ * **`output_currency`** (`str`): The 3-letter ISO code for the target currency (e.g., `"jpy"`).
43
+
44
+ #### Return Value
45
+ * Returns a formatted `str` representing the converted amount (e.g., `"10,450.50"`), or an error message string (`"Currency not available"`).
46
+
47
+ ---
48
+
49
+ ## Quickstart Examples
50
+
51
+ You can import and run the function directly in your Python workflow:
52
+
53
+ ```python
54
+ # Example 1: Converting a whole number (100 CAD to JPY)
55
+ result_1 = current_rates(100, "cad", "jpy")
56
+ # Output: Prints and returns the converted formatted string
57
+
58
+ # Example 2: Converting a precise decimal number (540.65 CAD to JPY)
59
+ result_2 = current_rates(540.65, "CAD", "JPY")
60
+ ```
61
+
62
+ ---
63
+
64
+ ## Limitations & Data Sources
65
+
66
+ * **No Real-Time Tracking:** Rates are updated once per day by the data provider.
67
+ * **System Clock Dependency:** The script relies on `datetime.date.today()`. Ensure your system time is accurate to pull the correct daily file.
68
+ * **Data Provider:** Powered by the [@fawazahmed0/currency-api]([(https://github.com/fawazahmed0/exchange-api])).
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "currency-convert"
3
+ version = "0.1.0"
4
+ description = "A simple library to convert an amount from one currency to another with rates updated daily. Powered by the Exchange API created by Fawaz Ahmed https://github.com/fawazahmed0/exchange-api"
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ dependencies = ["requests>=2.34.2"]
8
+
9
+ [[project.authors]]
10
+ name = "Faisal"
11
+ email = "faisal@nihongoproject.com"
12
+
13
+ [project.scripts]
14
+ currency-convert = "currency_convert:main"
15
+
16
+ [build-system]
17
+ requires = ["uv_build>=0.12.3,<0.13.0"]
18
+ build-backend = "uv_build"
@@ -0,0 +1,19 @@
1
+ [project]
2
+ name = "currency-convert"
3
+ version = "0.1.0"
4
+ description = "A simple library to convert an amount from one currency to another with rates updated daily. Powered by the Exchange API created by Fawaz Ahmed https://github.com/fawazahmed0/exchange-api"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Faisal", email = "faisal@nihongoproject.com" }
8
+ ]
9
+ requires-python = ">=3.14"
10
+ dependencies = [
11
+ "requests>=2.34.2",
12
+ ]
13
+
14
+ [project.scripts]
15
+ currency-convert = "currency_convert:main"
16
+
17
+ [build-system]
18
+ requires = ["uv_build>=0.12.3,<0.13.0"]
19
+ build-backend = "uv_build"
@@ -0,0 +1,2 @@
1
+ from .currency_api import current_rates
2
+ __all__ = ["current_rates"]
@@ -0,0 +1,343 @@
1
+ currencies = {
2
+ "1inch": "1inch",
3
+ "aave": "Aave",
4
+ "ada": "Cardano",
5
+ "aed": "Emirati Dirham",
6
+ "afn": "Afghan Afghani",
7
+ "agix": "SingularityNET",
8
+ "akt": "Akash Network",
9
+ "algo": "Algorand",
10
+ "all": "Albanian Lek",
11
+ "amd": "Armenian Dram",
12
+ "amp": "Amp",
13
+ "ang": "Dutch Guilder",
14
+ "aoa": "Angolan Kwanza",
15
+ "ape": "ApeCoin",
16
+ "apt": "Aptos",
17
+ "ar": "Arweave",
18
+ "arb": "Arbitrum",
19
+ "ars": "Argentine Peso",
20
+ "atom": "Cosmos",
21
+ "ats": "Austrian Schilling",
22
+ "aud": "Australian Dollar",
23
+ "avax": "Avalanche",
24
+ "awg": "Aruban or Dutch Guilder",
25
+ "axs": "Axie Infinity",
26
+ "azm": "Azerbaijani Manat",
27
+ "azn": "Azerbaijan Manat",
28
+ "bake": "BakeryToken",
29
+ "bam": "Bosnian Convertible Mark",
30
+ "bat": "Basic Attention Token",
31
+ "bbd": "Barbadian or Bajan Dollar",
32
+ "bch": "Bitcoin Cash",
33
+ "bdt": "Bangladeshi Taka",
34
+ "bef": "Belgian Franc",
35
+ "bgn": "Bulgarian Lev",
36
+ "bhd": "Bahraini Dinar",
37
+ "bif": "Burundian Franc",
38
+ "bmd": "Bermudian Dollar",
39
+ "bnb": "Binance Coin",
40
+ "bnd": "Bruneian Dollar",
41
+ "bob": "Bolivian Bolíviano",
42
+ "brl": "Brazilian Real",
43
+ "bsd": "Bahamian Dollar",
44
+ "bsv": "Bitcoin SV",
45
+ "bsw": "Biswap",
46
+ "btc": "Bitcoin",
47
+ "btcb": "Bitcoin BEP2",
48
+ "btg": "Bitcoin Gold",
49
+ "btn": "Bhutanese Ngultrum",
50
+ "btt": "BitTorrent",
51
+ "busd": "Binance USD",
52
+ "bwp": "Botswana Pula",
53
+ "byn": "Belarusian Ruble",
54
+ "byr": "Belarusian Ruble",
55
+ "bzd": "Belizean Dollar",
56
+ "cad": "Canadian Dollar",
57
+ "cake": "PancakeSwap",
58
+ "cdf": "Congolese Franc",
59
+ "celo": "Celo",
60
+ "cfx": "Conflux",
61
+ "chf": "Swiss Franc",
62
+ "chz": "Chiliz",
63
+ "clp": "Chilean Peso",
64
+ "cnh": "Chinese Yuan Renminbi Offshore",
65
+ "cny": "Chinese Yuan Renminbi",
66
+ "comp": "Compound",
67
+ "cop": "Colombian Peso",
68
+ "crc": "Costa Rican Colon",
69
+ "cro": "Crypto.com Chain",
70
+ "crv": "Curve DAO Token",
71
+ "cspr": "Casper",
72
+ "cuc": "Cuban Convertible Peso",
73
+ "cup": "Cuban Peso",
74
+ "cve": "Cape Verdean Escudo",
75
+ "cvx": "Convex Finance",
76
+ "cyp": "Cypriot Pound",
77
+ "czk": "Czech Koruna",
78
+ "dai": "DAI",
79
+ "dash": "Digital Cash",
80
+ "dcr": "Decred",
81
+ "dem": "German Deutsche Mark",
82
+ "dfi": "DfiStarter",
83
+ "djf": "Djiboutian Franc",
84
+ "dkk": "Danish Krone",
85
+ "doge": "Dogecoin",
86
+ "dop": "Dominican Peso",
87
+ "dot": "Polkadot",
88
+ "dydx": "dYdX",
89
+ "dzd": "Algerian Dinar",
90
+ "eek": "Estonian Kroon",
91
+ "egld": "Elrond",
92
+ "egp": "Egyptian Pound",
93
+ "enj": "Enjin Coin",
94
+ "eos": "EOS",
95
+ "ern": "Eritrean Nakfa",
96
+ "esp": "Spanish Peseta",
97
+ "etb": "Ethiopian Birr",
98
+ "etc": "Ethereum Classic",
99
+ "eth": "Ethereum",
100
+ "eur": "Euro",
101
+ "eurc": "",
102
+ "fei": "Fei USD",
103
+ "fil": "Filecoin",
104
+ "fim": "Finnish Markka",
105
+ "fjd": "Fijian Dollar",
106
+ "fkp": "Falkland Island Pound",
107
+ "flow": "Flow",
108
+ "flr": "FLARE",
109
+ "frax": "Frax",
110
+ "frf": "French Franc",
111
+ "ftt": "FarmaTrust",
112
+ "gala": "Gala",
113
+ "gbp": "British Pound",
114
+ "gel": "Georgian Lari",
115
+ "ggp": "Guernsey Pound",
116
+ "ghc": "Ghanaian Cedi",
117
+ "ghs": "Ghanaian Cedi",
118
+ "gip": "Gibraltar Pound",
119
+ "gmd": "Gambian Dalasi",
120
+ "gmx": "Goldmaxcoin",
121
+ "gnf": "Guinean Franc",
122
+ "gno": "Gnosis",
123
+ "grd": "Greek Drachma",
124
+ "grt": "The Graph",
125
+ "gt": "GateToken",
126
+ "gtq": "Guatemalan Quetzal",
127
+ "gusd": "Gemini US Dollar",
128
+ "gyd": "Guyanese Dollar",
129
+ "hbar": "Hedera",
130
+ "hkd": "Hong Kong Dollar",
131
+ "hnl": "Honduran Lempira",
132
+ "hnt": "Helium",
133
+ "hot": "Hydro Protocol",
134
+ "hrk": "Croatian Kuna",
135
+ "ht": "Huobi Token",
136
+ "htg": "Haitian Gourde",
137
+ "huf": "Hungarian Forint",
138
+ "icp": "Internet Computer",
139
+ "idr": "Indonesian Rupiah",
140
+ "iep": "Irish Pound",
141
+ "ils": "Israeli Shekel",
142
+ "imp": "Isle of Man Pound",
143
+ "imx": "Immutable X",
144
+ "inj": "Injective",
145
+ "inr": "Indian Rupee",
146
+ "iqd": "Iraqi Dinar",
147
+ "irr": "Iranian Rial",
148
+ "isk": "Icelandic Krona",
149
+ "itl": "Italian Lira",
150
+ "jep": "Jersey Pound",
151
+ "jmd": "Jamaican Dollar",
152
+ "jod": "Jordanian Dinar",
153
+ "jpy": "Japanese Yen",
154
+ "kas": "",
155
+ "kava": "Kava",
156
+ "kcs": "Kucoin",
157
+ "kda": "Kadena",
158
+ "kes": "Kenyan Shilling",
159
+ "kgs": "Kyrgyzstani Som",
160
+ "khr": "Cambodian Riel",
161
+ "klay": "Klaytn",
162
+ "kmf": "Comorian Franc",
163
+ "knc": "Kyber Network Crystals",
164
+ "kpw": "North Korean Won",
165
+ "krw": "South Korean Won",
166
+ "ksm": "Kusama",
167
+ "kwd": "Kuwaiti Dinar",
168
+ "kyd": "Caymanian Dollar",
169
+ "kzt": "Kazakhstani Tenge",
170
+ "lak": "Lao Kip",
171
+ "lbp": "Lebanese Pound",
172
+ "ldo": "Lido DAO Token",
173
+ "leo": "LEOcoin",
174
+ "link": "Chainlink",
175
+ "lkr": "Sri Lankan Rupee",
176
+ "lrc": "Loopring",
177
+ "lrd": "Liberian Dollar",
178
+ "lsl": "Basotho Loti",
179
+ "ltc": "Litecoin",
180
+ "ltl": "Lithuanian Litas",
181
+ "luf": "Luxembourg Franc",
182
+ "luna": "Terra",
183
+ "lunc": "",
184
+ "lvl": "Latvian Lat",
185
+ "lyd": "Libyan Dinar",
186
+ "mad": "Moroccan Dirham",
187
+ "mana": "Mana Coin Decentraland",
188
+ "mbx": "MobieCoin",
189
+ "mdl": "Moldovan Leu",
190
+ "mga": "Malagasy Ariary",
191
+ "mgf": "Malagasy Franc",
192
+ "mina": "Mina",
193
+ "mkd": "Macedonian Denar",
194
+ "mkr": "Maker",
195
+ "mmk": "Burmese Kyat",
196
+ "mnt": "Mongolian Tughrik",
197
+ "mop": "Macau Pataca",
198
+ "mro": "Mauritanian Ouguiya",
199
+ "mru": "Mauritanian Ouguiya",
200
+ "mtl": "Maltese Lira",
201
+ "mur": "Mauritian Rupee",
202
+ "mvr": "Maldivian Rufiyaa",
203
+ "mwk": "Malawian Kwacha",
204
+ "mxn": "Mexican Peso",
205
+ "mxv": "",
206
+ "myr": "Malaysian Ringgit",
207
+ "mzm": "Mozambican Metical",
208
+ "mzn": "Mozambican Metical",
209
+ "nad": "Namibian Dollar",
210
+ "near": "NEAR Protocol",
211
+ "neo": "NEO",
212
+ "nexo": "NEXO",
213
+ "nft": "NFT",
214
+ "ngn": "Nigerian Naira",
215
+ "nio": "Nicaraguan Cordoba",
216
+ "nlg": "Dutch Guilder",
217
+ "nok": "Norwegian Krone",
218
+ "npr": "Nepalese Rupee",
219
+ "nzd": "New Zealand Dollar",
220
+ "okb": "Okex",
221
+ "omr": "Omani Rial",
222
+ "one": "Menlo One",
223
+ "op": "Optimism",
224
+ "ordi": "",
225
+ "pab": "Panamanian Balboa",
226
+ "paxg": "PAX Gold",
227
+ "pen": "Peruvian Sol",
228
+ "pepe": "",
229
+ "pgk": "Papua New Guinean Kina",
230
+ "php": "Philippine Peso",
231
+ "pi": "Plian",
232
+ "pkr": "Pakistani Rupee",
233
+ "pln": "Polish Zloty",
234
+ "pol": "Proof Of Liquidity",
235
+ "pte": "Portuguese Escudo",
236
+ "pyg": "Paraguayan Guarani",
237
+ "qar": "Qatari Riyal",
238
+ "qnt": "Quant",
239
+ "qtum": "QTUM",
240
+ "rol": "Romanian Leu",
241
+ "ron": "Romanian Leu",
242
+ "rpl": "Rocket Pool",
243
+ "rsd": "Serbian Dinar",
244
+ "rub": "Russian Ruble",
245
+ "rune": "THORChain (ERC20)",
246
+ "rvn": "Ravencoin",
247
+ "rwf": "Rwandan Franc",
248
+ "sand": "The Sandbox",
249
+ "sar": "Saudi Arabian Riyal",
250
+ "sbd": "Solomon Islander Dollar",
251
+ "scr": "Seychellois Rupee",
252
+ "sdd": "Sudanese Dinar",
253
+ "sdg": "Sudanese Pound",
254
+ "sek": "Swedish Krona",
255
+ "sgd": "Singapore Dollar",
256
+ "shib": "Shiba Inu",
257
+ "shp": "Saint Helenian Pound",
258
+ "sit": "Slovenian Tolar",
259
+ "skk": "Slovak Koruna",
260
+ "sle": "Sierra Leonean Leone",
261
+ "sll": "Sierra Leonean Leone",
262
+ "snx": "Synthetix Network",
263
+ "sol": "Solana",
264
+ "sos": "Somali Shilling",
265
+ "spl": "Seborgan Luigino",
266
+ "srd": "Surinamese Dollar",
267
+ "srg": "Surinamese Guilder",
268
+ "ssp": "South Sudanese Pound",
269
+ "std": "Sao Tomean Dobra",
270
+ "stn": "Sao Tomean Dobra",
271
+ "stx": "Stacks",
272
+ "sui": "Sui",
273
+ "svc": "Salvadoran Colon",
274
+ "syp": "Syrian Pound",
275
+ "szl": "Swazi Lilangeni",
276
+ "thb": "Thai Baht",
277
+ "theta": "Theta",
278
+ "tjs": "Tajikistani Somoni",
279
+ "tmm": "Turkmenistani Manat",
280
+ "tmt": "Turkmenistani Manat",
281
+ "tnd": "Tunisian Dinar",
282
+ "top": "Tongan Pa'anga",
283
+ "trl": "",
284
+ "trx": "TRON",
285
+ "try": "Turkish Lira",
286
+ "ttd": "Trinidadian Dollar",
287
+ "tusd": "True USD",
288
+ "tvd": "Tuvaluan Dollar",
289
+ "twd": "Taiwan New Dollar",
290
+ "twt": "Trust Wallet Token",
291
+ "tzs": "Tanzanian Shilling",
292
+ "uah": "Ukrainian Hryvnia",
293
+ "ugx": "Ugandan Shilling",
294
+ "uni": "Uniswap",
295
+ "usd": "US Dollar",
296
+ "usdc": "USDC",
297
+ "usdd": "",
298
+ "usdp": "USDP Stablecoin",
299
+ "usdt": "Tether",
300
+ "uyu": "Uruguayan Peso",
301
+ "uzs": "Uzbekistani Som",
302
+ "val": "Vatican City Lira",
303
+ "veb": "Venezuelan Bolívar",
304
+ "ved": "",
305
+ "vef": "Venezuelan Bolívar",
306
+ "ves": "Venezuelan Bolívar",
307
+ "vet": "Vechain",
308
+ "vnd": "Vietnamese Dong",
309
+ "vuv": "Ni-Vanuatu Vatu",
310
+ "waves": "Waves",
311
+ "wemix": "WEMIX",
312
+ "woo": "WOO Network",
313
+ "wst": "Samoan Tala",
314
+ "xaf": "Central African CFA Franc BEAC",
315
+ "xag": "Silver Ounce",
316
+ "xau": "Gold Ounce",
317
+ "xaut": "Tether Gold",
318
+ "xbt": "",
319
+ "xcd": "East Caribbean Dollar",
320
+ "xcg": "Xchange",
321
+ "xch": "Chia",
322
+ "xdc": "XDC Network",
323
+ "xdr": "IMF Special Drawing Rights",
324
+ "xec": "Eternal Coin",
325
+ "xem": "NEM",
326
+ "xlm": "Stellar Lumen",
327
+ "xmr": "Monero",
328
+ "xof": "CFA Franc",
329
+ "xpd": "Palladium Ounce",
330
+ "xpf": "CFP Franc",
331
+ "xpt": "Platinum Ounce",
332
+ "xrp": "Ripple",
333
+ "xtz": "Tezos",
334
+ "yer": "Yemeni Rial",
335
+ "zar": "South African Rand",
336
+ "zec": "ZCash",
337
+ "zil": "Zilliqa",
338
+ "zmk": "Zambian Kwacha",
339
+ "zmw": "Zambian Kwacha",
340
+ "zwd": "Zimbabwean Dollar",
341
+ "zwg": "",
342
+ "zwl": "Zimbabwean Dollar"
343
+ }
@@ -0,0 +1,42 @@
1
+ import requests
2
+ from datetime import date, datetime
3
+
4
+ # API Variables
5
+ date = date.today()
6
+ apiVersion = "v1"
7
+
8
+
9
+ # Obtain Current Rates Function, date pulled from system and passed to date in API call
10
+ def current_rates(amount: float, input_currency: str, output_currency: str) -> str:
11
+ """
12
+ A function that takes three parameters to perform a currency conversion. The rates are pulled from the currency-api developed by Fawaz Ahmed. This function uses the current system date to pull the currency rates as of that date.
13
+
14
+ **Note**: The system date should be the correct date as other functions are available to perform historical conversions. The API does not update currency rates in real time, therefore this function is not suitable as a real time conversion tool for financial transactions.:
15
+ :param amount: A decimal amount to be converted. This can be a decimal number or a whole number.
16
+ :param input_currency: The currency of the amount parameter.
17
+ :param output_currency: The currency to which the amount will be converted.
18
+ :return: A formatted string with that is rounded to two decimal places.
19
+
20
+ **Example 1**: current_rates(100, "cad", "jpy")
21
+ Calling the function to convert 100 Canadian Dollars to Japanese Yen with the day's current rate.
22
+
23
+ **Example 2**: current_rates(540.65, "cad", "jpy")
24
+ An example of calling the function to convert 540.65 Canadian Dollars to Japanese Yen with the day's current rate. Notice that decimals can also be used for the amount parameter.
25
+ """
26
+
27
+ endpoint = f"currencies/{input_currency.lower()}.json"
28
+ url = f"https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@{date}/v1/{endpoint}"
29
+ r = requests.get(url)
30
+ data = r.json()
31
+ try:
32
+ base = input_currency.lower()
33
+ target = output_currency.lower()
34
+ rate = data[base][target]
35
+ converted: float = float(amount) * rate
36
+ result = f"{converted:,.2f}"
37
+ print(result)
38
+ return result
39
+ except KeyError:
40
+ error = "Currency not available"
41
+ print(error)
42
+ return error