Skip to content

Instantly share code, notes, and snippets.

@barisx
Last active August 6, 2022 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barisx/e30f3c18da2c6ded04308b70baae8270 to your computer and use it in GitHub Desktop.
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
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