Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. @cherrypy.expose
  2. def get_rate(self, currency):
  3. r = requests.get('http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml', stream=True)
  4. from xml.etree import ElementTree as ET
  5. tree = ET.parse(r.raw)
  6. root = tree.getroot()
  7. namespaces = {'ex': 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref'}
  8. for cube in root.findall('.//ex:Cube[@currency]', namespaces=namespaces):
  9. if (cube.attrib['currency'] == curr_from)
  10. return cube.attrib['rate']
  11. elif (cube.attrib['currency'] == curr_to)
  12. return cube.attrib['rate']
  13. else
  14. return 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement