Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @cherrypy.expose
- def get_rate(self, currency):
- r = requests.get('http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml', stream=True)
- from xml.etree import ElementTree as ET
- tree = ET.parse(r.raw)
- root = tree.getroot()
- namespaces = {'ex': 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref'}
- for cube in root.findall('.//ex:Cube[@currency]', namespaces=namespaces):
- if (cube.attrib['currency'] == curr_from)
- return cube.attrib['rate']
- elif (cube.attrib['currency'] == curr_to)
- return cube.attrib['rate']
- else
- return 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement