#NEWLINE# def get( self ) : #NEWLINE# #INDENT# codes = [ 'EUR' , 'JPY' , 'CNY' , 'CHF' , 'AUD' , 'TWD' , 'CAD' , 'GBP' , 'HKD' , 'MYR' , 'NZD' , 'PHP' , 'SGD' , 'THB' ] #NEWLINE# template_values = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# o = memcache . get ( 'currency.json' ) #NEWLINE# if ( o is not None ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for code in codes : #NEWLINE# #INDENT# url = ( 'http://www.google.com/ig/calculator?hl=en&q=1USD=?' + code ) #NEWLINE# response = urlfetch . fetch ( url ) #NEWLINE# m = re . findall ( 'rhs: "([0-9\\.]+)' , response . content ) #NEWLINE# if ( len ( m ) > 0 ) : #NEWLINE# #INDENT# value = m [ 0 ] . strip ( ) . replace ( ' ' , '' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# value = 0 #NEWLINE# #UNINDENT# template_values [ code . lower ( ) ] = value #NEWLINE# #UNINDENT# path = os . path . join ( os . path . dirname ( __file__ ) , 'tpl' , 'api' , 'currency.json' ) #NEWLINE# o = template . render ( path , template_values ) #NEWLINE# memcache . set ( 'currency.json' , o , 86400 ) #NEWLINE# #UNINDENT# self . write ( o )