-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from Oturum import legacy_session | ||
import xmltodict | ||
|
||
def kurGetir(kur_kodu:str = "USD"): | ||
""" | ||
TCMB'nin günlük döviz kurları XML dosyasından belirtilen döviz kurunu getirir. | ||
Args: | ||
kur_kodu (str): Döviz kuru kodu (örneğin, "USD"). | ||
Returns: | ||
str: Belirtilen döviz kurunun satış bilgilerini içeren string. | ||
""" | ||
kurlar = [] | ||
result = None | ||
|
||
url = "https://www.tcmb.gov.tr/kurlar/today.xml" | ||
oturum = legacy_session() | ||
try: | ||
response = oturum.get(url=url) | ||
response.raise_for_status() #response hatalarını yakalamak için | ||
data = xmltodict.parse(response.text) #xml verisini dict'e çevirir | ||
kurlar = [ kur for kur in data["Tarih_Date"].get("Currency")] #tüm kurlar listeye alınır | ||
|
||
except Exception as e: | ||
print(f"Döviz kuru getirilirken bir Hata oluştu: {e}") | ||
return None | ||
|
||
for kur in kurlar: | ||
if kur["@Kod"] == kur_kodu: | ||
result = kur | ||
break | ||
|
||
return result.get("ForexSelling") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,8 @@ | |
"requests", | ||
"pydantic", | ||
"parsel", | ||
"cssselect" | ||
"cssselect", | ||
"xmltodict" | ||
], | ||
|
||
# ? PyPI Bilgileri | ||
|