diff --git a/lokrez/smashgg.py b/lokrez/smashgg.py index baf40c5..3451ec0 100644 --- a/lokrez/smashgg.py +++ b/lokrez/smashgg.py @@ -18,7 +18,7 @@ API_URL = "{scheme}://{host}/{endpoint}".format( CHARACTERS = { c.smashggid : c.name for c in characters_ssbu.EVERYONE } -PLAYERSKINS = {} +GET_PLAYERDATA = lambda tag: {"tag": tag,} # ============================================================================= # ----------------------------------------------------------------------------- @@ -44,15 +44,20 @@ class Player(): self.seeding = int(seeding) self.twitterHandle = ( "" if twitterHandle is None else twitterHandle ) + try: + self.playerdata = GET_PLAYERDATA(self.gamerTag) + except: + self.playerdata = {} + # Check if there's a redirect in the players DB try: - self.gamerTag = PLAYERSKINS[self.gamerTag.lower()]["redirect"] + self.gamerTag = self.playerdata["tag"] except: pass # Prefix is superseeded by sponsors infos in DB try: - self.prefix = PLAYERSKINS[self.gamerTag.lower()]["sponsor"] + self.prefix = self.playerdata["sponsor"] except: pass @@ -71,7 +76,7 @@ class Player(): charname = character # Unknown char -> sgg id try: - skin = PLAYERSKINS[self.gamerTag.lower()]["skins"][charname] + skin = self.playerdata["skins"][charname] except KeyError: skin = "00" # default skin @@ -122,6 +127,21 @@ characters: {charslist}""" \ ) + # ------------------------------------------------------------------------- + def __str__(self): + # The char list looks like 'character1_skin1 (12.08), character2_skin2 + # (3.02)' where the number between parenthesis is the number of time + # the character was played + charslist = ", ".join( [ "{}_{} ({:.2f})".format(c,s,n) for (c,s),n in + sorted( self.chars.items(), key = lambda cv: cv[1], reverse = + True,) ]) + return "{plc}/ [{pfx}] {tag} -- {charslist}" \ + .format( + tag = self.gamerTag, + pfx = self.prefix, + plc = self.placement, + charslist = charslist, + ) # ----------------------------------------------------------------------------- class Tournament(): @@ -176,11 +196,27 @@ numEntrants: {nbe}""" \ # ------------------------------------------------------------------------- def clean_name(self, name_seo_delimiter): - if name_seo_delimiter is not None: + if name_seo_delimiter is not None and name_seo_delimiter != "": self.name = self.name.split(name_seo_delimiter)[0].strip() return self + # ------------------------------------------------------------------------- + def __str__(self): + return "Tournament {name} ({date} at {loc}), {nbe} entrants" \ + .format( + id = self.id, + name = self.name, + date = self.startAt, + loc = self.venueName, + addr = self.venueAddress, + city = self.city, + ctry = self.countryCode, + slug = self.slug, + nbe = self.numEntrants, + ) + + # ============================================================================= def run_query(