Welcome, guest | Sign In | My Account | Store | Cart
import string
import smtplib
import urllib2


# configure ur threshold rate, smtp server here 
# threshold rate for CAD --> USD noon rate 
thresholdRate=1.10
smtpServer='test-smtp-server'
fromaddr='foo@bar.com' 
toaddrs='you@corp.com'
# end of configuration

url='http://www.bankofcanada.ca/stats/assets/csv/fx-seven-day.csv'   
f=urllib2.urlopen(url,timeout=60)

data=f.read()
start=data.find('U.S. Dollar')
rate=data[start:].split('\n')[0].split(',')[-1]
if float(rate) > thresholdRate:
   #send email 
   msg = ('Subject: Bank of Canada Noon Foreign Exchange Rates %s for 1 USD ' % rate) 
   server = smtplib.SMTP(smtpServer)
   #server.set_debuglevel(1)
   server.sendmail(fromaddr, toaddrs, msg)
   server.quit()
f.close()

Diff to Previous Revision

--- revision 8 2009-08-18 05:45:06
+++ revision 9 2011-12-09 07:23:44
@@ -11,7 +11,7 @@
 toaddrs='you@corp.com'
 # end of configuration
 
-url='http://www.bankofcanada.ca/en/financial_markets/csv/exchange_eng.csv'   
+url='http://www.bankofcanada.ca/stats/assets/csv/fx-seven-day.csv'   
 f=urllib2.urlopen(url,timeout=60)
 
 data=f.read()

History