Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_date():
- try:
- d = "Unknown"
- fh = urllib.request.urlopen("http://www.bankofcanada.ca/en/markets/csv/exchange_eng.csv").read()
- for line in fh:
- line = line.strip()
- if not line or line.startsWith(("#", "Closing")):
- continue
- fields = line.split(",")
- if line.startsWith("Date"):
- d = fields[-1]
- else:
- try:
- value = float(fields[-1])
- rates[fields[0]] = value
- except ValueError:
- pass
- return "Exchange rates date: " + d
- except Exception as e:
- return "Failed to download:\n%s" % e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement