MCPcopy Create free account
hub / github.com/geekcomputers/Python / getVal

Function getVal

currency converter/main.py:11–25  ·  view source on GitHub ↗
(cont1, cont2)

Source from the content-addressed store, hash-verified

9
10
11def getVal(cont1, cont2):
12 # Extract currency codes from user input (format assumed like "USD- United States Dollar")
13 cont1val = cont1.split("-")[1]
14 cont2val = cont2.split("-")[1]
15 url = f"https://free.currconv.com/api/v7/convert?q={cont1val}_{cont2val}&compact=ultra&apiKey=b43a653672c4a94c4c26"
16 r = httpx.get(url)
17 htmlContent = r.content
18 soup = BeautifulSoup(htmlContent, "html.parser")
19 try:
20 # Extract the numeric value from the response text
21 valCurr = float(soup.get_text().split(":")[1].removesuffix("}")) # {USD:70.00}
22 except Exception:
23 print("Server down.")
24 exit()
25 return valCurr
26
27
28app = QtWidgets.QApplication([])

Callers 1

changeBtnFunction · 0.85

Calls 2

exitFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected