2020-07-06 19:54:42 -04:00
|
|
|
import argparse
|
2020-07-09 09:24:08 -04:00
|
|
|
import configparser
|
2020-07-07 10:13:56 -04:00
|
|
|
import datetime
|
2020-07-09 04:19:03 -04:00
|
|
|
import html
|
2020-07-20 12:44:49 -04:00
|
|
|
import json
|
2020-07-06 19:54:42 -04:00
|
|
|
import logging
|
2020-07-22 12:04:13 -04:00
|
|
|
import pathlib
|
2020-07-06 19:54:42 -04:00
|
|
|
import sys
|
|
|
|
|
2020-07-22 12:04:13 -04:00
|
|
|
import appdirs
|
|
|
|
|
|
|
|
from . import export
|
|
|
|
from . import resources
|
|
|
|
from . import smashgg
|
|
|
|
from . import version
|
2020-07-07 10:13:56 -04:00
|
|
|
|
2020-07-20 17:54:32 -04:00
|
|
|
# =============================================================================
|
|
|
|
__version__ = version.__version__
|
2020-07-22 12:04:13 -04:00
|
|
|
__license__ = version.__license__
|
|
|
|
|
|
|
|
ROOTDIR = pathlib.Path(__file__).absolute().parent
|
2020-07-06 19:54:42 -04:00
|
|
|
|
2020-07-22 12:04:13 -04:00
|
|
|
APPDIRS = appdirs.AppDirs(version.NAME, version.ENTITY)
|
2020-07-20 18:34:07 -04:00
|
|
|
|
2020-07-06 19:54:42 -04:00
|
|
|
# =============================================================================
|
|
|
|
def main():
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
2020-07-20 18:35:56 -04:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
formatter_class = argparse.ArgumentDefaultsHelpFormatter,
|
|
|
|
)
|
2020-07-06 19:54:42 -04:00
|
|
|
|
|
|
|
subparsers = parser.add_subparsers(
|
|
|
|
dest = "command",
|
|
|
|
help = "commands",
|
|
|
|
)
|
|
|
|
|
2020-07-20 18:35:56 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"--proxy", "-p",
|
|
|
|
default = None,
|
|
|
|
help = "the proxy to use",
|
|
|
|
)
|
2020-07-06 19:54:42 -04:00
|
|
|
|
2020-07-19 11:04:58 -04:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
init_parser = subparsers.add_parser(
|
|
|
|
"init",
|
2020-07-22 12:04:13 -04:00
|
|
|
formatter_class = argparse.ArgumentDefaultsHelpFormatter,
|
2020-07-19 11:04:58 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
init_parser.add_argument(
|
|
|
|
"game",
|
|
|
|
default = "ssbu",
|
|
|
|
help = "The game you want to initialize the resources for",
|
|
|
|
)
|
|
|
|
|
|
|
|
init_parser.add_argument(
|
|
|
|
"--imgdir", "-ID",
|
2020-07-22 12:04:13 -04:00
|
|
|
type = pathlib.Path,
|
|
|
|
default = pathlib.Path(APPDIRS.user_data_dir) / "res",
|
2020-07-19 11:04:58 -04:00
|
|
|
help = "The directory we should download the resources to",
|
|
|
|
)
|
|
|
|
|
2020-07-06 19:54:42 -04:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
top8_parser = subparsers.add_parser(
|
|
|
|
"top8",
|
2020-07-22 12:04:13 -04:00
|
|
|
formatter_class = argparse.ArgumentDefaultsHelpFormatter,
|
2020-07-06 19:54:42 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
top8_parser.add_argument(
|
|
|
|
"tournament",
|
|
|
|
default = None,
|
|
|
|
help = "The tournament slug or id",
|
|
|
|
)
|
2020-07-22 12:04:13 -04:00
|
|
|
|
|
|
|
top8_parser.add_argument(
|
|
|
|
"--token", "-t",
|
|
|
|
default = None,
|
|
|
|
help = "the authentication token to use",
|
|
|
|
)
|
|
|
|
|
2020-07-09 04:19:03 -04:00
|
|
|
top8_parser.add_argument(
|
|
|
|
"--imgdir", "-ID",
|
2020-07-22 12:04:13 -04:00
|
|
|
type = pathlib.Path,
|
|
|
|
default = pathlib.Path(APPDIRS.user_data_dir) / "res",
|
2020-07-20 18:34:07 -04:00
|
|
|
help = "The directories containing images, be careful whether " \
|
|
|
|
"you specify an absolute path or a relative one.",
|
2020-07-07 10:13:56 -04:00
|
|
|
)
|
2020-07-20 12:44:49 -04:00
|
|
|
top8_parser.add_argument(
|
|
|
|
"--playerskinsdb", "-PD",
|
2020-07-22 12:04:13 -04:00
|
|
|
type = pathlib.Path,
|
|
|
|
default = ROOTDIR / "data" / "playerskinsdb.json",
|
2020-07-20 18:34:07 -04:00
|
|
|
help = "A JSON file matching player tags, characters and " \
|
2020-07-20 12:44:49 -04:00
|
|
|
"preferred skins",
|
|
|
|
)
|
2020-07-07 10:13:56 -04:00
|
|
|
top8_parser.add_argument(
|
|
|
|
"--templatesdir", "-TD",
|
2020-07-22 12:04:13 -04:00
|
|
|
type = pathlib.Path,
|
|
|
|
default = ROOTDIR / "templates",
|
2020-07-07 10:13:56 -04:00
|
|
|
help = "The local result templates directory",
|
|
|
|
)
|
2020-07-06 19:54:42 -04:00
|
|
|
top8_parser.add_argument(
|
|
|
|
"--template", "-T",
|
2020-07-20 18:35:56 -04:00
|
|
|
default = "rebootlyon2020",
|
2020-07-06 19:54:42 -04:00
|
|
|
help = "The local result template to use",
|
|
|
|
)
|
2020-07-25 08:51:10 -04:00
|
|
|
top8_parser.add_argument(
|
|
|
|
"--template-options", "-O",
|
|
|
|
action = "append",
|
|
|
|
default = [],
|
|
|
|
help = "Template-specific options",
|
|
|
|
)
|
2020-07-06 19:54:42 -04:00
|
|
|
top8_parser.add_argument(
|
|
|
|
"--lkrz-file", "-f",
|
2020-07-22 12:04:13 -04:00
|
|
|
type = pathlib.Path,
|
2020-07-06 19:54:42 -04:00
|
|
|
default = None,
|
|
|
|
help = "The lkrz file in which the results are stored ; if it " \
|
|
|
|
"does not exist, one will be created from the smashgg data",
|
2020-07-19 16:26:34 -04:00
|
|
|
)
|
2020-07-07 10:13:56 -04:00
|
|
|
top8_parser.add_argument(
|
|
|
|
"--outfile", "-o",
|
2020-07-22 12:04:13 -04:00
|
|
|
type = pathlib.Path,
|
2020-07-07 10:13:56 -04:00
|
|
|
default = None,
|
2020-07-22 12:04:13 -04:00
|
|
|
help = "The SVG or PNG local result file to output to ; if it's " \
|
|
|
|
"not specified, it will use the tournament slug as name",
|
2020-07-19 16:26:34 -04:00
|
|
|
)
|
|
|
|
top8_parser.add_argument(
|
|
|
|
"--name-seo-delimiter",
|
|
|
|
default = None,
|
|
|
|
help = "A character that will delimit in a tournament name what " \
|
|
|
|
"really is its name, and what's actually here for SEO " \
|
|
|
|
"purposes (example: in 'Cornismash #42 - Ultimate Weekly " \
|
|
|
|
"Lyon', only the 'Cornismash #42' is the tournament name, "\
|
|
|
|
"the rest is here to help find the tournament).",
|
|
|
|
)
|
2020-07-07 10:13:56 -04:00
|
|
|
|
2020-07-06 19:54:42 -04:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
parser.add_argument( "--verbose", "-v",
|
|
|
|
default = 0,
|
|
|
|
action = "count",
|
|
|
|
help = "increase verbosity" )
|
|
|
|
|
|
|
|
parser.add_argument( "--version", "-V",
|
|
|
|
default = False,
|
|
|
|
action = "store_true",
|
|
|
|
help = "show version number" )
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Set log level
|
|
|
|
# -------------------------------------------------------------------------
|
2020-07-07 10:13:56 -04:00
|
|
|
log = logging.getLogger(version.NAME)
|
2020-07-06 19:54:42 -04:00
|
|
|
log.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
log_handler_console = logging.StreamHandler()
|
|
|
|
log_handler_console.setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
if(args.verbose >= 2):
|
|
|
|
log_handler_console.setLevel(logging.DEBUG)
|
|
|
|
elif(args.verbose >=1):
|
|
|
|
log_handler_console.setLevel(logging.INFO)
|
|
|
|
else:
|
|
|
|
log_handler_console.setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
log_formatter_console = logging.Formatter("%(name)s:%(levelname)s: %(message)s")
|
|
|
|
|
|
|
|
log_handler_console.setFormatter(log_formatter_console)
|
|
|
|
|
|
|
|
log.addHandler(log_handler_console)
|
|
|
|
|
|
|
|
# Print version if required
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
if args.version:
|
2020-07-07 10:13:56 -04:00
|
|
|
print(version.VERSION_NAME)
|
2020-07-09 08:31:22 -04:00
|
|
|
return 0
|
2020-07-06 19:54:42 -04:00
|
|
|
|
2020-07-07 10:13:56 -04:00
|
|
|
# -------------------------------------------------------------------------
|
2020-07-19 11:04:58 -04:00
|
|
|
if args.command not in [ "init", "top8" ]:
|
2020-07-07 10:13:56 -04:00
|
|
|
parser.print_help()
|
2020-07-09 08:31:22 -04:00
|
|
|
return 1
|
2020-07-07 10:13:56 -04:00
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
2020-07-19 11:04:58 -04:00
|
|
|
if args.command == "init":
|
2020-07-22 12:04:13 -04:00
|
|
|
args.imgdir.mkdir(parents=True, exist_ok=True)
|
2020-07-19 11:04:58 -04:00
|
|
|
resources.download_res_ssbu(
|
|
|
|
dstdir = args.imgdir,
|
2020-07-22 12:04:13 -04:00
|
|
|
proxy = args.proxy,
|
2020-07-19 11:04:58 -04:00
|
|
|
log = log,
|
|
|
|
)
|
|
|
|
return 0
|
|
|
|
# -------------------------------------------------------------------------
|
2020-07-07 10:13:56 -04:00
|
|
|
if args.command == "top8":
|
|
|
|
|
2020-07-20 12:44:49 -04:00
|
|
|
# Initialize PLAYERSKINS db
|
|
|
|
log.debug("loading playerskins db from '{}'" \
|
|
|
|
.format(args.playerskinsdb))
|
2020-07-22 14:28:42 -04:00
|
|
|
with args.playerskinsdb.open("r") as f:
|
2020-07-20 12:44:49 -04:00
|
|
|
smashgg.PLAYERSKINS = json.load(f)
|
|
|
|
|
|
|
|
#
|
2020-07-09 09:24:08 -04:00
|
|
|
tournament = None
|
|
|
|
top_players = {}
|
|
|
|
|
2020-07-22 12:04:13 -04:00
|
|
|
if args.lkrz_file is not None:
|
2020-07-09 09:24:08 -04:00
|
|
|
lkrz = configparser.ConfigParser()
|
2020-07-22 12:04:13 -04:00
|
|
|
lkrz.read(str(args.lkrz_file))
|
2020-07-09 09:24:08 -04:00
|
|
|
|
|
|
|
log.info("Loading data from '{}'".format(args.lkrz_file))
|
|
|
|
|
|
|
|
for s in lkrz:
|
|
|
|
section = lkrz[s]
|
|
|
|
if s == "Tournament":
|
|
|
|
tournament = smashgg.Tournament(
|
|
|
|
id = 0,
|
|
|
|
name = section["name"],
|
|
|
|
slug = section["slug"],
|
|
|
|
startAt = datetime.datetime.strptime(
|
|
|
|
section["date"],
|
|
|
|
"%Y-%m-%d %H:%M:%S",
|
|
|
|
),
|
|
|
|
numEntrants = int(section["numEntrants"]),
|
|
|
|
venueName = section["location"],
|
|
|
|
)
|
|
|
|
|
|
|
|
elif s.startswith("player "):
|
|
|
|
chars = {}
|
|
|
|
for char in section["characters"].split(","):
|
|
|
|
c = char.strip()
|
|
|
|
charname = c.split("_")[0]
|
|
|
|
charskin = c.split("_")[1].split(" ")[0]
|
|
|
|
charscore = float(c.split("(")[1].split(")")[0])
|
|
|
|
|
|
|
|
chars[(charname,charskin)] = charscore
|
|
|
|
|
|
|
|
player = smashgg.Player(
|
|
|
|
id = 0,
|
|
|
|
prefix = section["team"],
|
|
|
|
gamerTag = section["tag"],
|
|
|
|
placement = section["placement"],
|
|
|
|
seeding = section["seeding"],
|
|
|
|
chars = chars,
|
|
|
|
)
|
|
|
|
|
|
|
|
top_players[player.gamerTag] = player
|
|
|
|
|
2020-07-22 12:04:13 -04:00
|
|
|
else:
|
2020-07-07 10:13:56 -04:00
|
|
|
|
|
|
|
# Get infos from smash.gg and write the config file
|
|
|
|
tournament, top_players = getTournamentTop(
|
|
|
|
id_or_slug = args.tournament,
|
|
|
|
top = 8,
|
|
|
|
token = args.token,
|
|
|
|
proxy = args.proxy,
|
|
|
|
log = log,
|
|
|
|
)
|
|
|
|
|
|
|
|
if tournament is None or top_players is None:
|
|
|
|
log.error("Could not load data from smash.gg")
|
2020-07-09 08:31:22 -04:00
|
|
|
return 1
|
2020-07-07 10:13:56 -04:00
|
|
|
|
|
|
|
lkrz_data = "\n".join(
|
|
|
|
[ tournament.conf() ] \
|
|
|
|
+ list(map(
|
|
|
|
lambda p:p.conf(),
|
|
|
|
top_players.values(),
|
|
|
|
))
|
|
|
|
)
|
|
|
|
|
|
|
|
if args.lkrz_file is None:
|
2020-07-22 12:04:13 -04:00
|
|
|
args.lkrz_file = pathlib.Path(
|
|
|
|
"{}.lkrz".format(tournament.slug)
|
|
|
|
)
|
2020-07-07 10:13:56 -04:00
|
|
|
|
2020-07-22 14:28:42 -04:00
|
|
|
with args.lkrz_file.open("w", encoding="utf8") as f:
|
2020-07-07 10:13:56 -04:00
|
|
|
f.write(lkrz_data)
|
|
|
|
|
2020-07-09 09:24:08 -04:00
|
|
|
# Default outfile is 'tournament-slug.svg'
|
|
|
|
if args.outfile is None:
|
2020-07-22 12:04:13 -04:00
|
|
|
args.outfile = pathlib.Path(
|
|
|
|
"{}.svg".format(tournament.slug),
|
|
|
|
)
|
2020-07-09 09:24:08 -04:00
|
|
|
|
2020-07-09 08:31:22 -04:00
|
|
|
# Build the context which will be passed to the template
|
2020-07-22 14:28:42 -04:00
|
|
|
try:
|
|
|
|
dir_res_ssbu = args.imgdir.as_uri() # not absolute => error
|
|
|
|
except ValueError:
|
|
|
|
dir_res_ssbu = args.imgdir.as_posix()
|
|
|
|
|
2020-07-07 10:13:56 -04:00
|
|
|
context = {
|
2020-07-19 16:26:34 -04:00
|
|
|
"tournament": tournament.clean_name(args.name_seo_delimiter),
|
2020-07-07 10:13:56 -04:00
|
|
|
"players" : sorted(
|
|
|
|
top_players.values(),
|
|
|
|
key = lambda p: p.placement,
|
2020-07-08 01:53:21 -04:00
|
|
|
),
|
2020-07-22 14:28:42 -04:00
|
|
|
"dir_res_ssbu": dir_res_ssbu,
|
2020-07-25 08:51:10 -04:00
|
|
|
"dir_template": str(args.templatesdir / args.template),
|
|
|
|
"options": args.template_options,
|
2020-07-07 10:13:56 -04:00
|
|
|
}
|
|
|
|
|
2020-07-09 08:31:22 -04:00
|
|
|
rv = export.generate_outfile(
|
|
|
|
args.templatesdir,
|
|
|
|
args.template,
|
|
|
|
context,
|
|
|
|
args.outfile,
|
2020-07-22 12:04:13 -04:00
|
|
|
log = log,
|
|
|
|
cachedir = pathlib.Path(APPDIRS.user_cache_dir),
|
2020-07-09 08:31:22 -04:00
|
|
|
)
|
2020-07-07 10:13:56 -04:00
|
|
|
|
2020-07-09 08:31:22 -04:00
|
|
|
if rv is None:
|
|
|
|
return 1
|
2020-07-07 10:13:56 -04:00
|
|
|
|
2020-07-09 08:31:22 -04:00
|
|
|
log.info("Successfully saved outfile as '{}'".format(rv))
|
2020-07-07 10:13:56 -04:00
|
|
|
|
2020-07-09 08:31:22 -04:00
|
|
|
return 0
|
2020-07-07 10:13:56 -04:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
def getTournamentTop(
|
|
|
|
id_or_slug,
|
|
|
|
top=8,
|
|
|
|
token = "",
|
|
|
|
proxy = None,
|
|
|
|
log=None):
|
|
|
|
"""Returns a tuple : the smashgg.Tournament object and a list of the top
|
|
|
|
smashgg.Player in that tournament."""
|
|
|
|
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
# Select the right event (the one with the most entrants or the most sets)
|
|
|
|
def selectBiggestEvent(data, log=None):
|
|
|
|
|
|
|
|
try:
|
|
|
|
event = data["events"][0]
|
|
|
|
except:
|
|
|
|
log.error("No event found in data")
|
|
|
|
log.debug(data)
|
|
|
|
return None
|
|
|
|
|
|
|
|
try:
|
|
|
|
numEntrants = event["numEntrants"]
|
|
|
|
except KeyError:
|
|
|
|
numEntrants = event["standings"]["pageInfo"]["total"]
|
|
|
|
|
|
|
|
for e in data["events"]:
|
|
|
|
try:
|
|
|
|
ne = e["numEntrants"]
|
|
|
|
except KeyError:
|
|
|
|
ne = e["standings"]["pageInfo"]["total"]
|
|
|
|
|
|
|
|
if ne > numEntrants:
|
|
|
|
event = e
|
|
|
|
numEntrants = ne
|
|
|
|
|
|
|
|
log.info("Selected Event '{}' with {} entrants" \
|
|
|
|
.format(
|
|
|
|
event["name"],
|
|
|
|
numEntrants,
|
|
|
|
))
|
|
|
|
|
|
|
|
return event
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
data = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
data = smashgg.run_query(
|
|
|
|
query_name = "getTournamentTopById",
|
|
|
|
variables = {
|
|
|
|
"id" : int(id_or_slug), # If this fails, it's a slug
|
|
|
|
"top": top,
|
|
|
|
},
|
2020-07-22 12:04:13 -04:00
|
|
|
query_dir = ROOTDIR / "queries",
|
2020-07-07 10:13:56 -04:00
|
|
|
token = token,
|
|
|
|
proxy = proxy,
|
|
|
|
log = log,
|
|
|
|
)
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
data = smashgg.run_query(
|
|
|
|
query_name = "getTournamentTopBySlug",
|
|
|
|
variables = {
|
|
|
|
"slug" : id_or_slug,
|
|
|
|
"top": top,
|
|
|
|
},
|
2020-07-22 12:04:13 -04:00
|
|
|
query_dir = ROOTDIR / "queries",
|
2020-07-07 10:13:56 -04:00
|
|
|
token = token,
|
|
|
|
proxy = proxy,
|
|
|
|
log = log,
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
tournament_data = data["tournament"]
|
|
|
|
except:
|
|
|
|
log.error("Failed to load Tournaments")
|
|
|
|
return None,None
|
|
|
|
|
|
|
|
if tournament_data is None:
|
|
|
|
log.error("Failed to load Tournament")
|
|
|
|
return None,None
|
|
|
|
|
|
|
|
event = selectBiggestEvent(tournament_data, log)
|
|
|
|
|
|
|
|
if event is None :
|
|
|
|
return None,None
|
|
|
|
|
|
|
|
# Get the tournament
|
|
|
|
tournament = smashgg.Tournament(
|
|
|
|
id = tournament_data["id"],
|
|
|
|
slug = tournament_data["slug"],
|
|
|
|
name = tournament_data["name"],
|
|
|
|
startAt = \
|
|
|
|
datetime.datetime. \
|
|
|
|
fromtimestamp(tournament_data["startAt"]),
|
|
|
|
numEntrants = event["standings"]["pageInfo"]["total"],
|
|
|
|
venueAddress = tournament_data["venueAddress"],
|
|
|
|
venueName = tournament_data["venueName"],
|
|
|
|
city = tournament_data["city"],
|
|
|
|
countryCode = tournament_data["countryCode"],
|
|
|
|
hashtag = tournament_data["hashtag"],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Get the top players
|
|
|
|
top_players = {}
|
|
|
|
|
|
|
|
standings = event["standings"]["nodes"]
|
|
|
|
|
|
|
|
for standing in standings :
|
|
|
|
|
|
|
|
seeding = None
|
|
|
|
for seed in standing["entrant"]["seeds"]:
|
|
|
|
# Take the seeding from the phase with *all* Event entrants
|
|
|
|
if seed["phase"]["numSeeds"] == tournament.numEntrants:
|
|
|
|
seeding = seed["groupSeedNum"]
|
|
|
|
|
|
|
|
participant_data = standing["entrant"]["participants"][0]
|
|
|
|
|
|
|
|
try:
|
|
|
|
twitterHandle = participant_data \
|
|
|
|
["player"] \
|
|
|
|
["user"] \
|
|
|
|
["authorizations"] \
|
|
|
|
[0] \
|
|
|
|
["externalUsername"]
|
|
|
|
except TypeError:
|
|
|
|
twitterHandle = None
|
|
|
|
|
|
|
|
|
|
|
|
player = smashgg.Player(
|
|
|
|
id = standing["entrant"]["id"],
|
|
|
|
prefix = participant_data["prefix"],
|
|
|
|
gamerTag = participant_data["gamerTag"],
|
|
|
|
placement = standing["placement"],
|
|
|
|
seeding = seeding,
|
|
|
|
twitterHandle = twitterHandle,
|
|
|
|
)
|
|
|
|
|
|
|
|
top_players[player.id] = player
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
# Now, we need to find which characters those top players chose
|
|
|
|
data = None
|
|
|
|
|
|
|
|
data = smashgg.run_query(
|
|
|
|
query_name = "getCharsByTournamentIdAndEntrantIds",
|
|
|
|
variables = {
|
|
|
|
"tournamentId" : int(tournament.id),
|
|
|
|
"entrantIds": [ id for id in top_players.keys() ],
|
|
|
|
},
|
2020-07-22 12:04:13 -04:00
|
|
|
query_dir = ROOTDIR / "queries",
|
2020-07-07 10:13:56 -04:00
|
|
|
token = token,
|
|
|
|
proxy = proxy,
|
|
|
|
log = log,
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
tournament_data = data["tournament"]
|
|
|
|
except:
|
|
|
|
log.error("Failed to load Tournament")
|
|
|
|
return None,None
|
|
|
|
|
|
|
|
if tournament_data is None:
|
|
|
|
log.error("Failed to load Tournament")
|
|
|
|
return None,None
|
|
|
|
|
|
|
|
event = selectBiggestEvent(tournament_data, log)
|
|
|
|
|
|
|
|
if event is None :
|
|
|
|
return None,None
|
|
|
|
|
|
|
|
# TODO check that sets number is < to hardcoded 100 max value (cf query)
|
|
|
|
sets = event["sets"]["nodes"]
|
|
|
|
|
|
|
|
for s in sets:
|
|
|
|
try:
|
|
|
|
for g in s["games"]:
|
|
|
|
|
|
|
|
winnerId = g["winnerId"]
|
|
|
|
|
|
|
|
for slct in g["selections"]:
|
|
|
|
|
|
|
|
if slct["selectionType"] == "CHARACTER":
|
|
|
|
eid = slct["entrant"]["id"]
|
|
|
|
try:
|
|
|
|
top_players[eid].add_character_selection(
|
|
|
|
character = slct["selectionValue"],
|
|
|
|
win = (winnerId == eid),
|
|
|
|
)
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
except TypeError:
|
|
|
|
# If some games or selections are null, this can happen
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Return the data
|
|
|
|
return tournament, top_players
|
|
|
|
|
2020-07-06 19:54:42 -04:00
|
|
|
# =============================================================================
|
|
|
|
if __name__ == '__main__':
|
2020-07-09 08:31:22 -04:00
|
|
|
rv = main()
|
|
|
|
sys.exit(rv)
|
2020-07-22 12:04:13 -04:00
|
|
|
|