Use the multiple Games defined earlier
parent
e23294fd06
commit
71279eb2a2
|
@ -170,7 +170,7 @@ def download_res(
|
||||||
if "No Gamma Fix" in source_filename:
|
if "No Gamma Fix" in source_filename:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if character.codename not in source_filename:
|
if not any(c in source_filename for c in characters.codenames):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
target_filename = pathlib.Path(source_filename).name
|
target_filename = pathlib.Path(source_filename).name
|
||||||
|
@ -181,7 +181,7 @@ def download_res(
|
||||||
target_filename = pathlib.Path(source_filename).name
|
target_filename = pathlib.Path(source_filename).name
|
||||||
|
|
||||||
target_filename = target_filename.replace(
|
target_filename = target_filename.replace(
|
||||||
character.codename,
|
character.codenames[0],
|
||||||
character.name,
|
character.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import json
|
import json
|
||||||
import os, os.path
|
import os, os.path
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import pprint
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from .games import ssbu
|
from .games import ssbu, melee, pplus
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
API_HOST = "api.smash.gg"
|
API_HOST = "api.smash.gg"
|
||||||
|
@ -16,7 +17,11 @@ API_URL = "{scheme}://{host}/{endpoint}".format(
|
||||||
endpoint = API_ENDPOINT,
|
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,}
|
GET_PLAYERDATA = lambda tag: {"tag": tag,}
|
||||||
|
|
||||||
|
@ -67,11 +72,11 @@ class Player():
|
||||||
self.chars = chars
|
self.chars = chars
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
def add_character_selection(self, character, win):
|
def add_character_selection(self, game, character, win):
|
||||||
|
|
||||||
if type(character) != tuple:
|
if type(character) != tuple:
|
||||||
try:
|
try:
|
||||||
charname = CHARACTERS[character]
|
charname = CHARACTERS[game][character]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
charname = character # Unknown char -> sgg id
|
charname = character # Unknown char -> sgg id
|
||||||
|
|
||||||
|
@ -160,6 +165,7 @@ class Tournament():
|
||||||
city = None,
|
city = None,
|
||||||
countryCode = None,
|
countryCode = None,
|
||||||
hashtag = None,
|
hashtag = None,
|
||||||
|
game = None,
|
||||||
):
|
):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -172,11 +178,33 @@ class Tournament():
|
||||||
self.countryCode = countryCode
|
self.countryCode = countryCode
|
||||||
self.hashtag = hashtag
|
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):
|
def conf(self):
|
||||||
return """
|
return """
|
||||||
[Tournament]
|
[Tournament]
|
||||||
name: {name}
|
name: {name}
|
||||||
|
game: {game}
|
||||||
date: {date}
|
date: {date}
|
||||||
location: {loc} - {addr} ({city}, {ctry})
|
location: {loc} - {addr} ({city}, {ctry})
|
||||||
slug: {slug}
|
slug: {slug}
|
||||||
|
@ -184,6 +212,7 @@ numEntrants: {nbe}""" \
|
||||||
.format(
|
.format(
|
||||||
id = self.id,
|
id = self.id,
|
||||||
name = self.name,
|
name = self.name,
|
||||||
|
game = self.game,
|
||||||
date = self.startAt,
|
date = self.startAt,
|
||||||
loc = self.venueName,
|
loc = self.venueName,
|
||||||
addr = self.venueAddress,
|
addr = self.venueAddress,
|
||||||
|
@ -203,9 +232,10 @@ numEntrants: {nbe}""" \
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Tournament {name} ({date} at {loc}), {nbe} entrants" \
|
return "Tournament {game} {name} ({date} at {loc}), {nbe} entrants" \
|
||||||
.format(
|
.format(
|
||||||
id = self.id,
|
id = self.id,
|
||||||
|
game = self.game,
|
||||||
name = self.name,
|
name = self.name,
|
||||||
date = self.startAt,
|
date = self.startAt,
|
||||||
loc = self.venueName,
|
loc = self.venueName,
|
||||||
|
@ -281,6 +311,10 @@ def run_query(
|
||||||
.format(
|
.format(
|
||||||
rv_json["extensions"]["queryComplexity"],
|
rv_json["extensions"]["queryComplexity"],
|
||||||
))
|
))
|
||||||
|
log.debug("query result :\n{}" \
|
||||||
|
.format(
|
||||||
|
pprint.pformat(rv_json["data"]),
|
||||||
|
))
|
||||||
return rv_json["data"]
|
return rv_json["data"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue