Guest User

Untitled

a guest
Aug 30th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 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.split(b"\n"):
  7.             line = line.rstrip()
  8.             print(line)
  9.  
  10.             if not line or line.startswith(("#", "Closing")):
  11.                 continue
  12.  
  13.             fields = line.split(",")
  14.             if line.startswith("Date "):
  15.                 d = fields[-1]
  16.             else:
  17.                 try:
  18.                     value = float(fields[-1])
  19.                     rates[fields[0]] = value
  20.                 except ValueError:
  21.                     pass
  22.         return "Exchange rates date: " + d
  23.     except Exception as e:
  24.         return "Failed to download:\n%s" % e
Advertisement
Add Comment
Please, Sign In to add comment