Add lkrz file loading
Should you need to modify the lkrz file by hand and regenerate the outfile hereafter.master
parent
3302cff67f
commit
4714071968
|
@ -1,4 +1,5 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
import configparser
|
||||||
import datetime
|
import datetime
|
||||||
import html
|
import html
|
||||||
import logging
|
import logging
|
||||||
|
@ -120,10 +121,6 @@ def main():
|
||||||
if args.rootdir is None:
|
if args.rootdir is None:
|
||||||
args.rootdir = "." # TODO compute script root?
|
args.rootdir = "." # TODO compute script root?
|
||||||
|
|
||||||
# Default outfile is 'tournament-slug.svg'
|
|
||||||
if args.outfile is None:
|
|
||||||
args.outfile = "{}.svg".format(tournament.slug)
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
if args.command not in [ "top8" ]:
|
if args.command not in [ "top8" ]:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
@ -132,13 +129,55 @@ def main():
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
if args.command == "top8":
|
if args.command == "top8":
|
||||||
|
|
||||||
try:
|
tournament = None
|
||||||
with open(args.lkrz_file, "r") as f:
|
top_players = {}
|
||||||
# TODO parse config file to fill tournament & top_players
|
|
||||||
log.error("config file loading is not implemened yet")
|
try:
|
||||||
raise NotImplementedError
|
lkrz = configparser.ConfigParser()
|
||||||
|
lkrz.read(args.lkrz_file)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
|
||||||
|
log.warning(e)
|
||||||
|
|
||||||
except:
|
|
||||||
# Get infos from smash.gg and write the config file
|
# Get infos from smash.gg and write the config file
|
||||||
tournament, top_players = getTournamentTop(
|
tournament, top_players = getTournamentTop(
|
||||||
id_or_slug = args.tournament,
|
id_or_slug = args.tournament,
|
||||||
|
@ -166,6 +205,10 @@ def main():
|
||||||
with open(args.lkrz_file, "w", encoding="utf8") as f:
|
with open(args.lkrz_file, "w", encoding="utf8") as f:
|
||||||
f.write(lkrz_data)
|
f.write(lkrz_data)
|
||||||
|
|
||||||
|
# Default outfile is 'tournament-slug.svg'
|
||||||
|
if args.outfile is None:
|
||||||
|
args.outfile = "{}.svg".format(tournament.slug)
|
||||||
|
|
||||||
# Build the context which will be passed to the template
|
# Build the context which will be passed to the template
|
||||||
context = {
|
context = {
|
||||||
"tournament": tournament,
|
"tournament": tournament,
|
||||||
|
|
Loading…
Reference in New Issue