Use the multiple Games defined earlier

master
Lertsenem 2021-07-03 20:20:43 +02:00
parent e23294fd06
commit 71279eb2a2
2 changed files with 41 additions and 7 deletions

View File

@ -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,
)

View File

@ -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: