-
Notifications
You must be signed in to change notification settings - Fork 12
/
DovizKurlari.py
executable file
·107 lines (90 loc) · 2.96 KB
/
DovizKurlari.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python
# -*- coding:utf-8 -*-
# Tayfun ULU
# 2016
# 2020 - Flask ile restful-api ekleme ve sadece python3'e dondurme
import xml.etree.ElementTree as ET
from urllib.request import urlopen
class DovizKurlari():
def __init__(self):
pass
def __veri_update(self,zaman="Bugun"):
try :
if zaman == "Bugun":
self.url="http://www.tcmb.gov.tr/kurlar/today.xml"
else:
self.url=zaman
tree = ET.parse(urlopen(self.url))
root = tree.getroot()
self.son={}
self.Kur_Liste=[]
i = 0
for kurlars in root.findall('Currency'):
Kod= kurlars.get('Kod')
Unit = kurlars.find('Unit').text # <Unit>1</Unit>
isim = kurlars.find('Isim').text # <Isim>ABD DOLARI</Isim>
CurrencyName = kurlars.find('CurrencyName').text # <CurrencyName>US DOLLAR</CurrencyName>
ForexBuying = kurlars.find('ForexBuying').text # <ForexBuying>2.9587</ForexBuying>
ForexSelling = kurlars.find('ForexSelling').text # <ForexSelling>2.964</ForexSelling>
BanknoteBuying = kurlars.find('BanknoteBuying').text # <BanknoteBuying>2.9566</BanknoteBuying>
BanknoteSelling = kurlars.find('BanknoteSelling').text # <BanknoteSelling>2.9684</BanknoteSelling>
CrossRateUSD = kurlars.find('CrossRateUSD').text # <CrossRateUSD>1</CrossRateUSD>
self.Kur_Liste.append(Kod)
#self.son [Kod] = [Kod,isim,CurrencyName,Unit,ForexBuying,ForexSelling,BanknoteBuying,BanknoteSelling,CrossRateUSD]
self.son [Kod] = {
"Kod":Kod,
"isim":isim,
"CurrencyName":CurrencyName,
"Unit":Unit,
"ForexBuying":ForexBuying,
"ForexSelling":ForexSelling,
"BanknoteBuying":BanknoteBuying,
"BanknoteSelling":BanknoteSelling,
"CrossRateUSD":CrossRateUSD
}
return self.son
except :
return "HATA"
def DegerSor (self,*sor):
self.__veri_update()
if not(any(sor)):
return self.son
else:
return self.son.get(sor[0]).get(sor[1])
def Arsiv (self,Gun,Ay,Yil,*sor):
a=self.__veri_update(self.__Url_Yap(Gun,Ay,Yil))
if not(any(sor)):
if a == "HATA":
return {"Hata":"TATIL GUNU"}
return self.son
else :
if a == "HATA":
return "Tatil Gunu"
else:
return self.son.get(sor[0]).get(sor[1])
def Arsiv_tarih (self,Tarih="",*sor):
takvim = Tarih.split(".")
Gun = takvim[0]
Ay = takvim[1]
Yil = takvim[2]
a=self.__veri_update(self.__Url_Yap(Gun,Ay,Yil))
if not(any(sor)):
if a == "HATA":
return {"Hata":"TATIL GUNU"}
return self.son
else :
if a == "HATA":
return "Tatil Gunu"
else:
return self.son.get(sor[0]).get(sor[1])
def __Url_Yap (self,Gun,Ay,Yil):
if len (str(Gun)) == 1 :
Gun="0"+str(Gun)
if len (str(Ay)) == 1 :
Ay="0"+str(Ay)
self.url = ("http://www.tcmb.gov.tr/kurlar/"+str(Yil)+str(Ay)+"/"+str(Gun)+str(Ay)+str(Yil)+".xml")
return self.url
#Ornek Kullanım için
#from DovizKurlari import DovizKurlari
#ornek = DovizKurlari()
#print ornek.DegerSor("EUR",4)