<s> """<STR_LIT>""" <EOL> import logging <EOL> from json import loads as decode_json <EOL> from google . appengine . api import memcache <EOL> from google . appengine . api . urlfetch import fetch as urlfetch , POST <EOL> from google . appengine . ext import db <EOL> def render_number_with_commas ( n ) : <EOL> result = '<STR_LIT>' <EOL> while n >= <NUM_LIT:1000> : <EOL> n , r = divmod ( n , <NUM_LIT:1000> ) <EOL> result = "<STR_LIT>" % ( r , result ) <EOL> return "<STR_LIT>" % ( n , result ) <EOL> def get_exchange_rate_to_gbp ( currency , cache = { } ) : <EOL> if currency == '<STR_LIT>' : <EOL> return <NUM_LIT:1> <EOL> if currency in cache : <EOL> return cache [ currency ] <EOL> rate = memcache . get ( '<STR_LIT>' % currency ) <EOL> if rate : <EOL> return cache . setdefault ( currency , rate ) <EOL> url = "<STR_LIT>" % currency <EOL> try : <EOL> rate = float ( decode_json ( urlfetch ( url ) . content ) [ '<STR_LIT>' ] ) <EOL> except Exception , err : <EOL> logging . error ( "<STR_LIT>" % err ) <EOL> return <NUM_LIT:0> <EOL> memcache . set ( '<STR_LIT>' % currency , rate ) <EOL> return cache . setdefault ( currency , rate ) </s>
