From 4714071968d48abc61ddb221d3b216507d199f7f Mon Sep 17 00:00:00 2001 From: Lertsenem Date: Thu, 9 Jul 2020 15:24:08 +0200 Subject: [PATCH] Add lkrz file loading Should you need to modify the lkrz file by hand and regenerate the outfile hereafter. --- lokrez/__init__.py | 63 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/lokrez/__init__.py b/lokrez/__init__.py index 78351d2..32c6057 100644 --- a/lokrez/__init__.py +++ b/lokrez/__init__.py @@ -1,4 +1,5 @@ import argparse +import configparser import datetime import html import logging @@ -120,10 +121,6 @@ def main(): if args.rootdir is None: 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" ]: parser.print_help() @@ -132,13 +129,55 @@ def main(): # ------------------------------------------------------------------------- if args.command == "top8": - try: - with open(args.lkrz_file, "r") as f: - # TODO parse config file to fill tournament & top_players - log.error("config file loading is not implemened yet") - raise NotImplementedError + tournament = None + top_players = {} + + try: + 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 tournament, top_players = getTournamentTop( id_or_slug = args.tournament, @@ -166,6 +205,10 @@ def main(): with open(args.lkrz_file, "w", encoding="utf8") as f: 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 context = { "tournament": tournament,