Skip to content

Instantly share code, notes, and snippets.

@adililhan
Created March 2, 2012 23:43
Show Gist options
  • Save adililhan/1962454 to your computer and use it in GitHub Desktop.
Save adililhan/1962454 to your computer and use it in GitHub Desktop.

Revisions

  1. adililhan created this gist Mar 2, 2012.
    41 changes: 41 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #!/usr/bin/env python
    #-*-coding: utf-8-*-s

    __author__ = "Adil Ilhan"

    import requests
    import re

    class VeriCek(object):
    def __init__(self):
    self.r = requests.get("http://www.tcmb.gov.tr/kurlar/today.xml").content.decode('iso-8859-9').encode('utf-8')

    self.dolaralis = re.compile('<CurrencyName>US DOLLAR</CurrencyName><ForexBuying>(.*?)</ForexBuying>', re.I|re.U|re.S)
    self.dolarsatis = re.compile('<CurrencyName>US DOLLAR</CurrencyName><ForexBuying>.*?</ForexBuying><ForexSelling>(.*?)</ForexSelling>', re.I|re.U|re.S)
    self.euroalis = re.compile('<CurrencyName>EURO</CurrencyName><ForexBuying>(.*?)</ForexBuying>', re.I|re.U|re.S)
    self.eurosatis = re.compile('<CurrencyName>EURO</CurrencyName><ForexBuying>.*?</ForexBuying><ForexSelling>(.*?)</ForexSelling>', re.I|re.U|re.S)

    def regex(self):

    self.dolaralis = self.dolaralis.findall(self.r)
    self.dolarsatis = self.dolarsatis.findall(self.r)
    self.euroalis = self.euroalis.findall(self.r)
    self.eurosatis = self.eurosatis.findall(self.r)
    return self

    def getDolarAlis(self):
    return self.dolaralis[0]
    def getDolarSatis(self):
    return self.dolarsatis[0]
    def getEuroAlis(self):
    return self.euroalis[0]
    def getEuroSatis(self):
    return self.eurosatis[0]

    if __name__ == "__main__":
    doviz = VeriCek()
    doviz.regex()
    print "Dolar Satış: %s " %doviz.getDolarSatis()
    print "Dolar Alış: %s" % doviz.getDolarAlis()
    print "Euro Alış: %s" % doviz.getEuroAlis()
    print "Euro Satış: %s" % doviz.getEuroSatis()