5 changed files with 43 additions and 11 deletions
-
12aliases/key_aliases.tmpl
-
1aliases/key_dirs.tmpl
-
4dot_config/fish/config.fish.tmpl
-
8dot_config/i3blocks/i3blocks.conf.tmpl
-
29scripts/executable_currency
@ -0,0 +1,29 @@ |
|||
#!/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() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue