Advertisement
Guest User

Untitled

a guest
Aug 30th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. def get_date():
  2.     try:
  3.         d = "Unknown"
  4.         fh = urllib.request.urlopen("http://www.bankofcanada.ca/en/markets/csv/exchange_eng.csv").read()
  5.  
  6.         for line in fh:
  7.             line = line.strip()
  8.  
  9.             if not line or line.startsWith(("#", "Closing")):
  10.                 continue
  11.  
  12.             fields = line.split(",")
  13.             if line.startsWith("Date"):
  14.                 d = fields[-1]
  15.             else:
  16.                 try:
  17.                     value = float(fields[-1])
  18.                     rates[fields[0]] = value
  19.                 except ValueError:
  20.                     pass
  21.         return "Exchange rates date: " + d
  22.     except Exception as e:
  23.         return "Failed to download:\n%s" % e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement