From 71279eb2a26d3b66b86215f2db4f463fc14c2a1e Mon Sep 17 00:00:00 2001 From: Lertsenem Date: Sat, 3 Jul 2021 20:20:43 +0200 Subject: [PATCH] Use the multiple Games defined earlier --- lokrez/resources.py | 4 ++-- lokrez/smashgg.py | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/lokrez/resources.py b/lokrez/resources.py index 8e6fb3f..8788990 100644 --- a/lokrez/resources.py +++ b/lokrez/resources.py @@ -170,7 +170,7 @@ def download_res( if "No Gamma Fix" in source_filename: continue - if character.codename not in source_filename: + if not any(c in source_filename for c in characters.codenames): continue target_filename = pathlib.Path(source_filename).name @@ -181,7 +181,7 @@ def download_res( target_filename = pathlib.Path(source_filename).name target_filename = target_filename.replace( - character.codename, + character.codenames[0], character.name, ) diff --git a/lokrez/smashgg.py b/lokrez/smashgg.py index b1c3aec..0e754bc 100644 --- a/lokrez/smashgg.py +++ b/lokrez/smashgg.py @@ -1,10 +1,11 @@ import json import os, os.path import pathlib +import pprint import requests -from .games import ssbu +from .games import ssbu, melee, pplus # ============================================================================= API_HOST = "api.smash.gg" @@ -16,7 +17,11 @@ API_URL = "{scheme}://{host}/{endpoint}".format( endpoint = API_ENDPOINT, ) -CHARACTERS = { c.smashggid : c.name for c in ssbu.EVERYONE } +CHARACTERS = { + ssbu.GAME: { c.smashggid : c.name for c in ssbu.EVERYONE }, + melee.GAME: { c.smashggid : c.name for c in melee.EVERYONE }, + pplus.GAME: { c.smashggid : c.name for c in pplus.EVERYONE }, + } GET_PLAYERDATA = lambda tag: {"tag": tag,} @@ -67,11 +72,11 @@ class Player(): self.chars = chars # ------------------------------------------------------------------------- - def add_character_selection(self, character, win): + def add_character_selection(self, game, character, win): if type(character) != tuple: try: - charname = CHARACTERS[character] + charname = CHARACTERS[game][character] except KeyError: charname = character # Unknown char -> sgg id @@ -160,6 +165,7 @@ class Tournament(): city = None, countryCode = None, hashtag = None, + game = None, ): self.id = id self.name = name @@ -172,11 +178,33 @@ class Tournament(): self.countryCode = countryCode self.hashtag = hashtag + # --------------------------------------------------------------------- + def parse_game(id_or_name): + for g in [ ssbu, melee, pplus ]: + if type(id_or_name) == int: + if g.GAME.smashggid == id_or_name: + return g.GAME + elif type(id_or_name) == str: + if id_or_name in g.GAME.list_names(): + return g.GAME + return None + # --------------------------------------------------------------------- + + if type(game) == dict: + self.game = parse_game(game["id"]) + if self.game is None: + self.game = parse_game(game["name"]) + elif type(game) in [int, str]: + self.game = parse_game(game) + else: + self.game = game + # ------------------------------------------------------------------------- def conf(self): return """ [Tournament] name: {name} +game: {game} date: {date} location: {loc} - {addr} ({city}, {ctry}) slug: {slug} @@ -184,6 +212,7 @@ numEntrants: {nbe}""" \ .format( id = self.id, name = self.name, + game = self.game, date = self.startAt, loc = self.venueName, addr = self.venueAddress, @@ -203,9 +232,10 @@ numEntrants: {nbe}""" \ # ------------------------------------------------------------------------- def __str__(self): - return "Tournament {name} ({date} at {loc}), {nbe} entrants" \ + return "Tournament {game} {name} ({date} at {loc}), {nbe} entrants" \ .format( id = self.id, + game = self.game, name = self.name, date = self.startAt, loc = self.venueName, @@ -281,6 +311,10 @@ def run_query( .format( rv_json["extensions"]["queryComplexity"], )) + log.debug("query result :\n{}" \ + .format( + pprint.pformat(rv_json["data"]), + )) return rv_json["data"] except KeyError: try: