Last active
August 6, 2022 16:47
-
-
Save barisx/e30f3c18da2c6ded04308b70baae8270 to your computer and use it in GitHub Desktop.
Turkiye Cumhuriyeti Merkez Bankasi Dolar Kuru Alma Python, Get Central Bank of the Republic of Turkey Dollar Currency Function
This file contains 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 xmltodict | |
import json | |
import requests as r | |
import re | |
from decimal import * | |
var = {"link": "https://www.tcmb.gov.tr/kurlar/today.xml", "col_name": "Tarih_Date"} | |
def get_dollar(): | |
global var | |
tcmb = r.get(var.get("link")) | |
_json = xmltodict.parse(re.sub(u"[^\x20-\x7f]+",u"", tcmb.text)) | |
return Decimal(_json[var.get("col_name")]["Currency"][0]["ForexSelling"]) \ | |
.quantize(Decimal('.01'), rounding=ROUND_UP) # USD | |
def get_dollar_as_string(): | |
return str(get_dollar()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment