--- currency/!Currency/py/Rates.py 2004/02/20 20:49:53 51 +++ currency/!Currency/py/Rates.py 2004/03/09 18:25:43 52 @@ -1,15 +1,11 @@ # > !Currency.py.Rates/py import pickle -import re import string +import time import urllib -_re_date = re.compile(r"EFFECTIVE *(\d\d-\w\w\w-\d\d)") -_re_rate = re.compile(r"([A-Z]{3,3}) ([^0-9]+?) +([0-9.]+)? +([0-9.]+)( +)?([^0-9]*)$") - - def load(cache): global _date, _rates c = open(cache, 'r') @@ -23,25 +19,14 @@ rates = [(us, dollar, 1.0)] u = urllib.urlopen(url) c = open(cache, 'w') + _date = time.strftime('%d %b %Y') while 1: l = u.readline() - m = _re_date.match(l) - if m: - break - _date = m.group(1) - while 1: - l = u.readline() - if l[:4] == 'CODE': - break - l = u.readline() - while 1: - l = u.readline() - m = _re_rate.match(l[:-2]) - if m is None: + if l == '': break - rates.append((string.capwords(string.lower(m.group(2))), - string.capwords(string.lower(m.group(6))), - eval(m.group(4)))) + l = l[:-1] + m = string.split(l, ' ', 1) + rates.append(('', m[1], eval(m[0]))) u.close() pickle.dump(_date, c, 1) _rates = rates