Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions currency converter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@


def getVal(cont1, cont2):
# Extract currency codes from user input (format assumed like "USD- United States Dollar")
cont1val = cont1.split("-")[1]
cont2val = cont2.split("-")[1]
url = f"https://free.currconv.com/api/v7/convert?q={cont1val}_{cont2val}&compact=ultra&apiKey=b43a653672c4a94c4c26"
r = httpx.get(url)
htmlContent = r.content
soup = BeautifulSoup(htmlContent, "html.parser")
try:
# Extract the numeric value from the response text
valCurr = float(soup.get_text().split(":")[1].removesuffix("}")) # {USD:70.00}
except Exception:
print("Server down.")
Expand Down