stuff
This commit is contained in:
28
.local/bin/brl_to_usd.py
Executable file
28
.local/bin/brl_to_usd.py
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def brl_to_usd(amount_brl):
|
||||
url = f"https://api.exchangerate.host/convert?from=BRL&to=USD&amount={amount_brl}"
|
||||
try:
|
||||
response = requests.get(url, timeout=5)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
usd = data["result"]
|
||||
print(f"R${amount_brl:.2f} BRL = ${usd:.2f} USD")
|
||||
except Exception as e:
|
||||
print(f"Error converting currency: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: ./brl_to_usd.py <amount_in_brl>")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
amount = float(sys.argv[1])
|
||||
brl_to_usd(amount)
|
||||
except ValueError:
|
||||
print("Please provide a valid number.")
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user