<s> import json <EOL> import datetime <EOL> import urllib2 <EOL> from time import sleep <EOL> class SteamError ( Exception ) : <EOL> pass <EOL> class SteamAPI : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , steam_id , api_key ) : <EOL> """<STR_LIT>""" <EOL> self . api_key = api_key <EOL> self . steam_id = steam_id <EOL> self . time = <NUM_LIT:10> <EOL> self . retries = <NUM_LIT:3> <EOL> def _get_json ( self , url , params = None ) : <EOL> """<STR_LIT>""" <EOL> if params is None : <EOL> return json . load ( self . _open_url ( url ) ) <EOL> else : <EOL> return json . load ( self . _open_url ( url % params ) ) <EOL> def _open_url ( self , url ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return urllib2 . urlopen ( url ) <EOL> except urllib2 . URLError as e : <EOL> print '<STR_LIT>' + str ( e . reason ) <EOL> except urllib2 . HTTPError as e : <EOL> print '<STR_LIT>' + str ( e . code ) <EOL> return self . _retry ( self , url , self . time , self . tries ) <EOL> except ValueError as e : <EOL> print '<STR_LIT>' <EOL> except : <EOL> return self . _retry ( url , self . time , self . retries ) <EOL> def _retry ( self , url ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" . format ( url , self . retries ) <EOL> for num in range ( self . retries ) : <EOL> try : <EOL> return urllib2 . urlopen ( url ) <EOL> except : <EOL> sleep ( self . time ) <EOL> raise SteamError ( '<STR_LIT>' ) <EOL> def _date ( self , date ) : <EOL> return datetime . datetime . fromtimestamp ( int ( date ) ) . strftime ( '<STR_LIT>' ) </s>
