Dotfiles for my tiling window manager + terminal workflow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

29 lines
923 B

#!/usr/bin/env python3
import sys
import requests
def convert_currency(amount, from_currency, to_currency):
url = f"https://api.frankfurter.app/latest?amount={amount}&from={from_currency}&to={to_currency}"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
converted_amount = data['rates'][to_currency]
print(f"{amount} {from_currency} = {converted_amount} {to_currency}")
else:
print("Error: Unable to fetch exchange rates.")
def main():
if len(sys.argv) != 4:
print("Usage: currency_converter.py <amount> <from_currency> <to_currency>")
print("Example: currency_converter.py 100 CAD USD")
sys.exit(1)
amount = float(sys.argv[3])
from_currency = sys.argv[1].upper()
to_currency = sys.argv[2].upper()
convert_currency(amount, from_currency, to_currency)
if __name__ == "__main__":
main()