Last active
April 26, 2022 20:16
-
-
Save Kenan7/59f9473933caa6083b2ea99790cf0674 to your computer and use it in GitHub Desktop.
Get currency from CBAR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
from datetime import date | |
import requests | |
from logzero import logger | |
''' | |
value = CurrencyCbar().get_one_try() | |
''' | |
class CurrencyCbar: | |
def __init__(self): | |
''' | |
dd/mm/YY | |
''' | |
self.today = date.today().strftime("%d.%m.%Y") | |
r = requests.get(f"https://www.cbar.az/currencies/{self.today}.xml") | |
self.tree = ET.fromstring(str(r.text)) | |
def get_one_usd(self) -> float: | |
return float( | |
self.tree.findall(".//*[@Code='USD']")[0].find("Value").text | |
) | |
def get_one_try(self) -> float: | |
return float( | |
self.tree.findall(".//*[@Code='TRY']")[0].find("Value").text | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment