<s> import urllib <EOL> import json <EOL> from PyQt4 . Qt import QThread <EOL> class Ticker ( QThread ) : <EOL> def __init__ ( self , source , currency , url , fields , interval , callback ) : <EOL> QThread . __init__ ( self ) <EOL> self . source = source <EOL> self . url = url <EOL> self . fields = fields <EOL> self . interval = interval <EOL> self . callback = callback <EOL> def run ( self ) : <EOL> self . sleep ( <NUM_LIT:5> ) <EOL> while True : <EOL> try : <EOL> f = urllib . urlopen ( self . url ) <EOL> data = f . read ( ) <EOL> feed = json . loads ( data ) <EOL> rate = feed <EOL> for field in self . fields : <EOL> rate = rate [ field ] <EOL> rate = float ( rate ) <EOL> self . callback ( rate , self . source ) <EOL> except ( ValueError , KeyError ) : <EOL> print "<STR_LIT>" <EOL> except IOError : <EOL> print "<STR_LIT>" <EOL> self . sleep ( self . interval ) </s>
