/[james]/currency/!Currency/py/Rates.py
ViewVC logotype

Diff of /currency/!Currency/py/Rates.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 51 by james, Mon Feb 10 18:25:55 2003 UTC revision 52 by james, Tue Mar 9 18:25:43 2004 UTC
# Line 1  Line 1 
1  # > !Currency.py.Rates/py  # > !Currency.py.Rates/py
2    
3  import pickle  import pickle
 import re  
4  import string  import string
5    import time
6  import urllib  import urllib
7    
8    
 _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]*)$")  
   
   
9  def load(cache):  def load(cache):
10      global _date, _rates      global _date, _rates
11      c = open(cache, 'r')      c = open(cache, 'r')
# Line 23  def update(url, cache, us, dollar): Line 19  def update(url, cache, us, dollar):
19      rates = [(us, dollar, 1.0)]      rates = [(us, dollar, 1.0)]
20      u = urllib.urlopen(url)      u = urllib.urlopen(url)
21      c = open(cache, 'w')      c = open(cache, 'w')
22        _date = time.strftime('%d %b %Y')
23      while 1:      while 1:
24          l = u.readline()          l = u.readline()
25          m = _re_date.match(l)          if 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:  
26              break              break
27          rates.append((string.capwords(string.lower(m.group(2))),          l = l[:-1]
28                        string.capwords(string.lower(m.group(6))),          m = string.split(l, ' ', 1)
29                        eval(m.group(4))))          rates.append(('', m[1], eval(m[0])))
30      u.close()      u.close()
31      pickle.dump(_date, c, 1)      pickle.dump(_date, c, 1)
32      _rates = rates      _rates = rates

Legend:
Removed from v.51  
changed lines
  Added in v.52

  ViewVC Help
Powered by ViewVC 1.1.26