__author__ = "Matt Croydon - http://postneo.com" __version__ = "0.0.4" __license__ = "BSD" __copyright__ = "Copyright (c) 2005 Matt Croydon." import appuifw import e32 import urllib e32.ao_yield() class QuoteGrab: def __init__(self): self.lock = e32.Ao_lock() self.old_title = appuifw.app.title appuifw.app.title = u"QuoteGrab" self.exit_flag = False appuifw.app.exit_key_handler = self.abort self.stock = u'' self.got_data = False def abort(self): # Exit-key handler. self.exit_flag = True self.lock.signal() def get_stock(self): self.stock = appuifw.query(u'Enter a stock symbol', 'text', u'NOK') def handle_error(self, errorstr): err = u'Error: %s' % errorstr appuifw.note(err, 'error') self.abort() def display_stock(self): text = u'Retreiving graph for %s' % self.stock appuifw.note(text, 'info') url = 'http://ichart.finance.yahoo.com/b?s=%s' % self.stock try: urllib.urlretrieve(url, 'C:\\stock.gif') self.got_data = True except IOError, (errno, strerror): self.handle_error(strerror) if self.got_data == True: content_handler = appuifw.Content_handler(self.lock.signal) content_handler.open('c:\\stock.gif') self.lock.wait() def cleanup(self): appuifw.app.title = self.old_title print "QuoteGrab done." def main(): app = QuoteGrab() app.get_stock() app.display_stock() app.cleanup() if __name__ == "__main__": main()