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

  1. #!/usr/bin/env python3
  2. import sys
  3. import requests
  4. def convert_currency(amount, from_currency, to_currency):
  5. url = f"https://api.frankfurter.app/latest?amount={amount}&from={from_currency}&to={to_currency}"
  6. response = requests.get(url)
  7. if response.status_code == 200:
  8. data = response.json()
  9. converted_amount = data['rates'][to_currency]
  10. print(f"{amount} {from_currency} = {converted_amount} {to_currency}")
  11. else:
  12. print("Error: Unable to fetch exchange rates.")
  13. def main():
  14. if len(sys.argv) != 4:
  15. print("Usage: currency_converter.py <amount> <from_currency> <to_currency>")
  16. print("Example: currency_converter.py 100 CAD USD")
  17. sys.exit(1)
  18. amount = float(sys.argv[3])
  19. from_currency = sys.argv[1].upper()
  20. to_currency = sys.argv[2].upper()
  21. convert_currency(amount, from_currency, to_currency)
  22. if __name__ == "__main__":
  23. main()