28 Commits 04a13878e8 ... 33410c044b

Author SHA1 Message Date
  Lertsenem 33410c044b Merge branch 'master' && bump version 1 year ago
  Lertsenem 8522d51719 Fix typos 1 year ago
  Lertsenem 980d2d7f47 Merge branch 'master' && bump version 1 year ago
  Lertsenem 27c4c3c00c Bump version to 4 1 year ago
  Lertsenem 6d6d26e384 Merge branch 'master' into multismash 1 year ago
  Lertsenem c5e2e062b8 Fix seeding infos 1 year ago
  Lertsenem 21cb648422 Fix getCharsByTour... query complexity 1 year ago
  Lertsenem 217f3ab95a Add melee chars smashgg ids 1 year ago
  Lertsenem 1fc572debe Fix resources dl for melee 1 year ago
  Lertsenem 06a67559fb Fix Palutena position 1 year ago
  Lertsenem 0ebfd6853f Fix character position: sephiroth 1 year ago
  Lertsenem 90535b9675 Change Twitch stream from rebootlyon to smashlyon 1 year ago
  Lertsenem 89b78d1125 Add new character: Kazuya 1 year ago
  Lertsenem abc2d82ca1 Add characters missing smashgg id 1 year ago
  Lertsenem d811ef6577 Add character corrections for rebootlyon2020 1 year ago
  Lertsenem 8de436f55c Change Richter and Cloud charcorr 2 years ago
  Lertsenem 18a4b6674e Add the multiple games feature 1 year ago
  Lertsenem 7b9d3f13f4 Fix GraphQL queries following API change 1 year ago
  Lertsenem 71279eb2a2 Use the multiple Games defined earlier 1 year ago
  Lertsenem e23294fd06 Remove generate_outfile function 1 year ago
  Lertsenem 0bf4a7dc0e Add Games class 1 year ago
  Lertsenem b3a963fec4 Fix typos 1 year ago
  Lertsenem 7df05f1f08 Add character corrections for rebootlyon2020 1 year ago
  Lertsenem beaf3aaa87 Change Richter and Cloud charcorr 2 years ago
  Lertsenem 7dd02cef5c Change Robin charcorrs 2 years ago
  Lertsenem 4854993a23 Update lokrez workflow to fit other smash games 2 years ago
  Lertsenem b75e78f89a Update the resdl function for more than just ssbu 2 years ago
  Lertsenem 3d1c2e6b20 Add other smash games base data 2 years ago

+ 1 - 1
LICENSE

@@ -1,6 +1,6 @@
1 1
 MIT License
2 2
 
3
-Copyright (c) 2020 Lertsenem   
3
+Copyright (c) 2020 Lertsenem
4 4
 
5 5
 Permission is hereby granted, free of charge, to any person obtaining a copy
6 6
 of this software and associated documentation files (the "Software"), to deal

+ 1 - 1
README.adoc

@@ -55,7 +55,7 @@ them for you and rename them according to lokrez expectations. Use it with
55 55
 +lokrez init ssbu+. Then you can go make yourself a cup of coffee or two,
56 56
 because that's about 3G you're going to download.
57 57
 
58
-By default, the images are 
58
+By default, the images are
59 59
 
60 60
 For reference, the images names look like :
61 61
 

+ 438 - 158
lokrez/__init__.py

@@ -1,10 +1,13 @@
1 1
 import argparse
2 2
 import configparser
3
+import copy
3 4
 import datetime
4 5
 import html
6
+import io
5 7
 import json
6 8
 import logging
7 9
 import pathlib
10
+import pprint
8 11
 import requests
9 12
 import sys
10 13
 import urllib
@@ -16,6 +19,8 @@ from . import resources
16 19
 from . import smashgg
17 20
 from . import version
18 21
 
22
+from .games import ssbu, pplus, melee
23
+
19 24
 # =============================================================================
20 25
 __version__ = version.__version__
21 26
 __license__ = version.__license__
@@ -30,6 +35,62 @@ LOG_DUMMY.addHandler(logging.NullHandler())
30 35
 DEFAULT_DIR_TEMPLATES = ROOTDIR / "templates"
31 36
 
32 37
 # =============================================================================
38
+class StoreOptionKeyPair(argparse.Action):
39
+    def __init__(
40
+            self,
41
+            option_strings,
42
+            dest,
43
+            nargs=1,
44
+            const=None,
45
+            default=None,
46
+            type=None,
47
+            choices=None,
48
+            required=False,
49
+            help=None,
50
+            metavar="KEY=VALUE",
51
+            ):
52
+
53
+        if nargs == 0:
54
+            raise ValueError(
55
+                    'nargs for append actions must be > 0; if arg '
56
+                    'strings are not supplying the value to append, '
57
+                    'the append const action may be more appropriate'
58
+                    )
59
+        if const is not None and nargs != '?':
60
+            raise ValueError('nargs must be %r to supply const' % '?')
61
+
62
+        super(StoreOptionKeyPair, self).__init__(
63
+                option_strings=option_strings,
64
+                dest=dest,
65
+                nargs=nargs,
66
+                const=const,
67
+                default=default,
68
+                type=type,
69
+                choices=choices,
70
+                required=required,
71
+                help=help,
72
+                metavar=metavar,
73
+                )
74
+
75
+    def __call__(self, parser, namespace, values, option_string=None):
76
+        try:
77
+            options = getattr(namespace, self.dest)
78
+        except AttributeError:
79
+            options = {}
80
+
81
+        for kv in values:
82
+            try:
83
+                k,v = kv.split("=")
84
+            except ValueError:
85
+                k = kv
86
+                v = True
87
+
88
+            options[k] = v
89
+
90
+        setattr(namespace, self.dest, options)
91
+
92
+
93
+# =============================================================================
33 94
 def get_templates_list(
34 95
         dir_templates = DEFAULT_DIR_TEMPLATES,
35 96
         ):
@@ -46,6 +107,76 @@ def get_templates_list(
46 107
     return templates_list
47 108
 
48 109
 # =============================================================================
110
+def get_infos_from_file(
111
+        lkrz_file_path,
112
+        options = {},
113
+        outform = "dict",
114
+        log = LOG_DUMMY,
115
+        ):
116
+
117
+    if not lkrz_file_path.exists():
118
+        raise IOError( "lkrz file '{}' does not exist" \
119
+                .format(str(lkrz_file_path)) )
120
+
121
+    lkrz = configparser.ConfigParser()
122
+    lkrz.read(str(lkrz_file_path))
123
+
124
+    log.info("Loading data from '{}'".format(str(lkrz_file_path)))
125
+
126
+    if s in lkrz:
127
+        section = lkrz[s]
128
+        if s == "Tournament":
129
+            tournament = smashgg.Tournament(
130
+                    id = 0,
131
+                    name = section["name"],
132
+                    game = section["game"],
133
+                    slug = section["slug"],
134
+                    startAt = datetime.datetime.strptime(
135
+                        section["date"],
136
+                        "%Y-%m-%d %H:%M:%S",
137
+                        ),
138
+                    numEntrants = int(section["numEntrants"]),
139
+                    venueName = section["location"],
140
+                    ) \
141
+                            .clean_name(
142
+                                    options.get("name_seo_delimiter", None)
143
+                                    )
144
+
145
+        elif s.startswith("player "):
146
+            chars = {}
147
+            for char in section["characters"].split(","):
148
+                c = char.strip()
149
+                charname = c.split("_")[0]
150
+                charskin = c.split("_")[1].split(" ")[0]
151
+                charscore = float(c.split("(")[1].split(")")[0])
152
+
153
+                chars[(charname,charskin)] = charscore
154
+
155
+            player = smashgg.Player(
156
+                    id = 0,
157
+                    prefix = section["team"],
158
+                    gamerTag = section["tag"],
159
+                    placement = section["placement"],
160
+                    seeding = section["seeding"],
161
+                    twitterHandle = section["twitter"],
162
+                    chars = chars,
163
+                    )
164
+
165
+            top_players[player.gamerTag] = player
166
+
167
+    # Re-sort top players by their placement
168
+    top_players = sorted(
169
+            top_players.values(),
170
+            key = lambda p: p.placement,
171
+            )
172
+
173
+    return format_infos(
174
+            outform,
175
+            tournament,
176
+            top_players,
177
+            )
178
+
179
+# =============================================================================
49 180
 def get_infos_from_url(
50 181
         url,
51 182
         token,
@@ -64,24 +195,75 @@ def get_infos_from_url(
64 195
         raise ValueError("Unsupported outform")
65 196
 
66 197
     # -------------------------------------------------------------------------
198
+    tournament = None
199
+    event = None
200
+
201
+    # -------------------------------------------------------------------------
67 202
     if url_parsed.netloc == "smash.gg":
68 203
 
69 204
         if (url_parsed.path.split("/")[1] != "tournament"):
70
-            raise Exception("No tournament found in url {}".format(url_parsed.path.split("/")))
205
+            log.error("Incomplete URL '{}'".format(url))
206
+            raise Exception("No tournament found in url {}".format(url))
71 207
 
72
-        # Get infos from smash.gg and write the config file
73
-        tournament, top_players = getTournamentTop(
74
-                id_or_slug = url_parsed.path.split("/")[2],
75
-                get_prefixes = options.get("use_smashgg_prefixes", False),
76
-                top = top,
77
-                token = token,
78
-                proxy = proxy,
79
-                log = log,
80
-                )
208
+        try:
209
+            tournament = url_parsed.path.split("/")[2]
210
+        except:
211
+            log.error("Incomplete URL '{}'".format(url))
212
+            raise Exception("No tournament slug found in url {}".format(url))
81 213
 
82
-        if tournament is None or top_players is None:
83
-            log.error("Could not load data from smash.gg")
84
-            raise Exception("Could not load data from smash.gg")
214
+        try:
215
+            if (url_parsed.path.split("/")[3] == "event"):
216
+                event = url_parsed.path.split("/")[4]
217
+        except:
218
+            log.info("No event slug found in url")
219
+
220
+    # -------------------------------------------------------------------------
221
+    return get_infos_from_id_or_slug(
222
+            id_or_slug = tournament,
223
+            event_slug = event,
224
+            token = token,
225
+            options = options,
226
+            outform = outform,
227
+            top = top,
228
+            proxy = proxy,
229
+            log = log,
230
+            )
231
+
232
+# =============================================================================
233
+def get_infos_from_id_or_slug(
234
+        id_or_slug,
235
+        event_slug = None,
236
+        token = "",
237
+        options = [],
238
+        outform = "dict",
239
+        top = 8,
240
+        proxy = None,
241
+        log = LOG_DUMMY,
242
+        ):
243
+    # Get infos from smash.gg and write the config file
244
+    tournament, top_players = getTournamentTop(
245
+            id_or_slug = id_or_slug,
246
+            event_slug = event_slug,
247
+            import_options = options,
248
+            top = top,
249
+            token = token,
250
+            proxy = proxy,
251
+            log = log,
252
+            )
253
+
254
+    if tournament is None or top_players is None:
255
+        log.error("Could not load data from smash.gg")
256
+        raise Exception("Could not load data from smash.gg")
257
+
258
+    return format_infos(outform, tournament, top_players)
259
+
260
+
261
+# =============================================================================
262
+def format_infos(
263
+        outform,
264
+        tournament,
265
+        top_players,
266
+        ):
85 267
 
86 268
     # -------------------------------------------------------------------------
87 269
     if outform == "dict":
@@ -101,6 +283,41 @@ def get_infos_from_url(
101 283
                         )
102 284
 
103 285
 # =============================================================================
286
+def init_resources(
287
+        imgdir,
288
+        game,
289
+        source = None,
290
+        store_raw = False,
291
+        proxy = None,
292
+        log = LOG_DUMMY,
293
+        ):
294
+
295
+    # Create imgdir
296
+    imgdir.mkdir(parents=True, exist_ok=True)
297
+
298
+    # Start resources download according to game
299
+    if game in ssbu.GAME.list_names():
300
+        game = ssbu
301
+    elif game in melee.GAME.list_names():
302
+        game = melee
303
+    elif game in pplus.GAME.list_names():
304
+        game = pplus
305
+    else:
306
+        log.error("Unknown game '{}'".format(game))
307
+        return 1
308
+
309
+    resources.download_res(
310
+            dstdir = imgdir,
311
+            game = game,
312
+            source = source,
313
+            store_raw = store_raw,
314
+            proxy = proxy,
315
+            log = log,
316
+            )
317
+
318
+    return 0
319
+
320
+# =============================================================================
104 321
 def generate_pic(
105 322
         infos_or_lkrzfile = None,
106 323
         template = None,
@@ -112,12 +329,20 @@ def generate_pic(
112 329
         log = LOG_DUMMY,
113 330
         ):
114 331
 
332
+    if outform.startswith("."):
333
+        outform = outform[1:]
334
+
115 335
     if outform not in ["svg", "png"]:
116 336
         raise Exception("Unsupported outform")
117 337
 
118 338
     if type(infos_or_lkrzfile) == str:
119
-        # TODO : load lkrz as dict infos
120
-        raise NotImplementedError()
339
+        # load lkrz as dict infos
340
+        infos = get_infos_from_file(
341
+                lkrz_file_path = pathlib.Path(infos_or_lkrzfile),
342
+                options = options,
343
+                outform = "dict",
344
+                log = log,
345
+                )
121 346
     else:
122 347
         infos = infos_or_lkrzfile
123 348
 
@@ -136,7 +361,7 @@ def generate_pic(
136 361
                 ),
137 362
             "dir_res_ssbu": dir_res,
138 363
             "dir_template": str(dir_templates/template),
139
-            "options": options.get("template_options", []),
364
+            "options": options,
140 365
             }
141 366
 
142 367
     pic = export.generate_pic(
@@ -146,7 +371,7 @@ def generate_pic(
146 371
             outform,
147 372
             log = log,
148 373
             cachedir = dir_cache,
149
-            options = { "svg_embed_png": options.get("svg_embed_png",False) },
374
+            options = options,
150 375
             )
151 376
 
152 377
     if pic is None:
@@ -186,12 +411,25 @@ def main():
186 411
             )
187 412
 
188 413
     init_parser.add_argument(
414
+            "--source", "-s",
415
+            default = None,
416
+            choices = ["spriters", "smashlyon"],
417
+            help = "From where should the resources images be downloaded",
418
+            )
419
+
420
+    init_parser.add_argument(
189 421
             "--imgdir", "-ID",
190 422
             type = pathlib.Path,
191 423
             default = pathlib.Path(APPDIRS.user_data_dir) / "res",
192 424
             help = "The directory we should download the resources to",
193 425
             )
194 426
 
427
+    init_parser.add_argument(
428
+            "--raw", "-r",
429
+            action = "store_true",
430
+            help = "Download the raw zipfiles instead of extracting them",
431
+            )
432
+
195 433
     # -------------------------------------------------------------------------
196 434
     top8_parser = subparsers.add_parser(
197 435
             "top8",
@@ -201,13 +439,22 @@ def main():
201 439
     top8_parser.add_argument(
202 440
             "tournament",
203 441
             default = None,
204
-            help = "The tournament slug or id",
442
+            help = "The tournament url, slug or id",
205 443
             )
206 444
 
207 445
     top8_parser.add_argument(
208 446
             "--token", "-t",
209 447
             default = None,
210
-            help = "the authentication token to use",
448
+            help = "the authentication token to use ; needed if you're " \
449
+                   "generating the top8 from a smash.gg url",
450
+            )
451
+
452
+    top8_parser.add_argument(
453
+            "--playerskinsdb", "-P",
454
+            type = (lambda s: s if s.startswith("http") else pathlib.Path(s)),
455
+            default = ROOTDIR / "data" / "playerskinsdb.json",
456
+            help = "A JSON file path or url matching player tags, characters,"\
457
+                   " sponsors, and preferred skins",
211 458
             )
212 459
 
213 460
     top8_parser.add_argument(
@@ -218,13 +465,6 @@ def main():
218 465
                    "you specify an absolute path or a relative one.",
219 466
             )
220 467
     top8_parser.add_argument(
221
-            "--playerskinsdb", "-PD",
222
-            type = (lambda s: s if s.startswith("http") else pathlib.Path(s)),
223
-            default = ROOTDIR / "data" / "playerskinsdb.json",
224
-            help = "A JSON file path or url matching player tags, characters,"\
225
-                   " sponsors, and preferred skins",
226
-            )
227
-    top8_parser.add_argument(
228 468
             "--cachedir", "-CD",
229 469
             type = pathlib.Path,
230 470
             default = pathlib.Path(APPDIRS.user_cache_dir),
@@ -243,48 +483,44 @@ def main():
243 483
             help = "The local result template to use",
244 484
             )
245 485
     top8_parser.add_argument(
246
-            "--template-options", "-O",
247
-            action = "append",
248
-            default = [],
249
-            help = "Template-specific options",
486
+            "--template-options", "-TO",
487
+            nargs="+",
488
+            action = StoreOptionKeyPair,
489
+            default = {},
490
+            help = "Template-specific options (like 'covid' or 'animated')",
250 491
             )
251 492
     top8_parser.add_argument(
252
-            "--export-options", "-E",
253
-            action = "append",
254
-            default = [],
255
-            help = "Export options (like svg_embed_png)",
493
+            "--export-options", "-EO",
494
+            nargs="+",
495
+            action = StoreOptionKeyPair,
496
+            default = {},
497
+            help = "Export options (like 'svg_embed_png')",
256 498
             )
257 499
 
258 500
     top8_parser.add_argument(
259
-            "--lkrz-file", "-f",
260
-            type = pathlib.Path,
261
-            default = None,
262
-            help = "The lkrz file in which the results are stored ; if it " \
263
-                   "does not exist, one will be created from the smashgg data",
501
+            "--import-options", "-IO",
502
+            nargs="+",
503
+            action = StoreOptionKeyPair,
504
+            default = {},
505
+            help = "Import options (like 'use_smashgg_prefixes')",
264 506
             )
507
+
265 508
     top8_parser.add_argument(
266 509
             "--outfile", "-o",
267 510
             type = pathlib.Path,
268 511
             default = None,
269 512
             help = "The SVG or PNG local result file to output to ; if it's " \
270
-                   "not specified, it will use the tournament slug as name",
513
+                   "not specified, it will default to SVG and use the "       \
514
+                   "tournament slug as name ; if you're generating a "        \
515
+                   "localresult from a url, a LKRZ file with the same name "  \
516
+                   "will also be generated along the image file (unless you " \
517
+                   "use the --no-lkrz flag).",
271 518
             )
272 519
 
273
-    top8_parser.add_argument(
274
-            "--name-seo-delimiter",
275
-            default = None,
276
-            help = "A character that will delimit in a tournament name what " \
277
-                   "really is its name, and what's actually here for SEO "    \
278
-                   "purposes (example: in 'Cornismash #42 - Ultimate Weekly " \
279
-                   "Lyon', only the 'Cornismash #42' is the tournament name, "\
280
-                   "the rest is here to help find the tournament).",
281
-            )
282
-    top8_parser.add_argument(
283
-            "--use-smashgg-prefixes", "-P",
284
-            action = "store_true",
285
-            help = "Use the prefixes (sponsor, team, etc) set by players on " \
286
-                   "smash.gg for the tournament",
287
-                   )
520
+    parser.add_argument( "--no-lkrz", "-nl",
521
+                         default = False,
522
+                         action = "store_true",
523
+                         help = "Do not output a LKRZ file" )
288 524
 
289 525
     # -------------------------------------------------------------------------
290 526
     parser.add_argument( "--verbose", "-v",
@@ -321,26 +557,38 @@ def main():
321 557
 
322 558
     log.addHandler(log_handler_console)
323 559
 
560
+    # Print all arguments in debug
561
+    # -------------------------------------------------------------------------
562
+    log.debug( "Command arguments:\n{}".format( pprint.pformat(vars(args))) )
563
+
324 564
     # Print version if required
325 565
     # -------------------------------------------------------------------------
326 566
     if args.version:
327 567
         print(version.VERSION_NAME)
328 568
         return 0
329 569
 
570
+    # Check if command is recognized
330 571
     # -------------------------------------------------------------------------
331 572
     if args.command not in [ "init", "top8" ]:
332 573
         parser.print_help()
333 574
         return 1
334 575
 
576
+    # -- init
335 577
     # -------------------------------------------------------------------------
336 578
     if args.command == "init":
337
-        args.imgdir.mkdir(parents=True, exist_ok=True)
338
-        resources.download_res_ssbu(
339
-                dstdir = args.imgdir,
579
+
580
+        rv = init_resources(
581
+                imgdir = args.imgdir,
582
+                game = args.game,
583
+                source = args.source,
584
+                store_raw = args.raw,
340 585
                 proxy = args.proxy,
341 586
                 log = log,
342 587
                 )
343
-        return 0
588
+
589
+        return rv
590
+
591
+    # -- top8
344 592
     # -------------------------------------------------------------------------
345 593
     if args.command == "top8":
346 594
 
@@ -358,87 +606,58 @@ def main():
358 606
         #
359 607
         tournament = None
360 608
         top_players = {}
609
+        lkrz_file = None
361 610
 
362
-        if args.lkrz_file is not None and args.lkrz_file.exists():
363
-            lkrz = configparser.ConfigParser()
364
-            lkrz.read(str(args.lkrz_file))
365
-
366
-            log.info("Loading data from '{}'".format(args.lkrz_file))
367
-
368
-            for s in lkrz:
369
-                section = lkrz[s]
370
-                if s == "Tournament":
371
-                    tournament = smashgg.Tournament(
372
-                            id = 0,
373
-                            name = section["name"],
374
-                            slug = section["slug"],
375
-                            startAt = datetime.datetime.strptime(
376
-                                section["date"],
377
-                                "%Y-%m-%d %H:%M:%S",
378
-                                ),
379
-                            numEntrants = int(section["numEntrants"]),
380
-                            venueName = section["location"],
381
-                            )
382
-
383
-                elif s.startswith("player "):
384
-                    chars = {}
385
-                    for char in section["characters"].split(","):
386
-                        c = char.strip()
387
-                        charname = c.split("_")[0]
388
-                        charskin = c.split("_")[1].split(" ")[0]
389
-                        charscore = float(c.split("(")[1].split(")")[0])
390
-
391
-                        chars[(charname,charskin)] = charscore
392
-
393
-                    player = smashgg.Player(
394
-                            id = 0,
395
-                            prefix = section["team"],
396
-                            gamerTag = section["tag"],
397
-                            placement = section["placement"],
398
-                            seeding = section["seeding"],
399
-                            twitterHandle = section["twitter"],
400
-                            chars = chars,
401
-                            )
611
+        all_options = {
612
+                **args.import_options,
613
+                **args.template_options,
614
+                **args.export_options,
615
+                }
402 616
 
403
-                    top_players[player.gamerTag] = player
617
+        # Determine the nature of the 'tournament' argument :
618
+        # - url
619
+        # - id or slug
620
+        # - lkrz file
621
+        # url
622
+        if (    args.tournament.startswith("http://")
623
+             or args.tournament.startswith("https://") ):
624
+            infos = get_infos_from_url(
625
+                    url = args.tournament,
626
+                    token = args.token,
627
+                    options = args.import_options,
628
+                    outform = "dict",
629
+                    top = 8,
630
+                    proxy = args.proxy,
631
+                    log = log,
632
+                    )
404 633
 
405
-            # Re-sort top players by their placement
406
-            top_players = sorted(
407
-                    top_players.values(),
408
-                    key = lambda p: p.placement,
634
+        # lkrz file
635
+        elif pathlib.Path(args.tournament).exists():
636
+            infos = get_infos_from_file(
637
+                    lkrz_file_path = pathlib.Path(args.tournament),
638
+                    options = args.import_options,
639
+                    outform = "dict",
640
+                    log = log,
409 641
                     )
410 642
 
643
+        # id or slug
411 644
         else:
412
-
413
-            # Get infos from smash.gg and write the config file
414
-            tournament, top_players = getTournamentTop(
645
+            infos = get_infos_from_id_or_slug(
415 646
                     id_or_slug = args.tournament,
416
-                    get_prefixes = args.use_smashgg_prefixes,
417
-                    top = 8,
418 647
                     token = args.token,
648
+                    options = args.import_options,
649
+                    outform = "dict",
650
+                    top = 8,
419 651
                     proxy = args.proxy,
420 652
                     log = log,
421 653
                     )
422 654
 
423
-            if tournament is None or top_players is None:
424
-                log.error("Could not load data from smash.gg")
425
-                return 1
426
-
427
-            lkrz_data = "\n".join(
428
-                    [ tournament.conf() ] \
429
-                    + list(map(
430
-                        lambda p:p.conf(),
431
-                        top_players,
432
-                        ))
433
-                    )
655
+        tournament = infos["tournament"]
656
+        top_players = infos["players"]
434 657
 
435
-            if args.lkrz_file is None:
436
-                args.lkrz_file = pathlib.Path(
437
-                        "{}.lkrz".format(tournament.slug)
438
-                        )
439
-
440
-            with args.lkrz_file.open("w", encoding="utf8") as f:
441
-                f.write(lkrz_data)
658
+        if tournament is None or top_players is None:
659
+            log.error("Could not load data")
660
+            return 1
442 661
 
443 662
         # Default outfile is 'tournament-slug.svg'
444 663
         if args.outfile is None:
@@ -446,48 +665,60 @@ def main():
446 665
                     "{}.svg".format(tournament.slug),
447 666
                     )
448 667
 
449
-        # Build the context which will be passed to the template
668
+        # Save a lkrz file
669
+        if not args.no_lkrz:
670
+            lkrz_data = format_infos("lkrz", tournament, top_players)
671
+            lkrz_file = args.outfile.with_suffix(".lkrz")
672
+
673
+            with lkrz_file.open("w", encoding="utf8") as f:
674
+                f.write(lkrz_data)
675
+
676
+        # If the outfile we were asked for was a .lkrz, we're done
677
+        if args.outfile.suffix == ".lkrz":
678
+            return 0
679
+
680
+        # Otherwise, let's generate the picture file
681
+        # First build the context which will be passed to the template
450 682
         try:
451
-            dir_res_ssbu = args.imgdir.as_uri() # not absolute => error
683
+            dir_res = (args.imgdir / tournament.game.name).as_uri() # not absolute => error
452 684
         except ValueError:
453
-            dir_res_ssbu = args.imgdir.as_posix()
454
-
455
-        context = {
456
-                "tournament": tournament.clean_name(args.name_seo_delimiter),
457
-                "players" : sorted(
458
-                    top_players,
459
-                    key = lambda p: p.placement,
460
-                    ),
461
-                "dir_res_ssbu": dir_res_ssbu,
462
-                "dir_template": str(args.templatesdir / args.template),
463
-                "options": args.template_options,
464
-                }
465
-
466
-        rv = export.generate_outfile(
467
-                args.templatesdir,
468
-                args.template,
469
-                context,
470
-                args.outfile,
685
+            dir_res = (args.imgdir / tournament.game.name).as_posix()
686
+
687
+        pic = generate_pic(
688
+                infos_or_lkrzfile = infos,
689
+                template = args.template,
690
+                outform = args.outfile.suffix,
691
+                options = all_options,
692
+                dir_templates = args.templatesdir,
693
+                dir_res = dir_res,
694
+                dir_cache = args.cachedir,
471 695
                 log = log,
472
-                cachedir = args.cachedir,
473
-                options={"svg_embed_png": "svg_embed_png" in args.export_options},
474 696
                 )
475 697
 
476
-        if rv is None:
698
+        if pic is None:
477 699
             return 1
478 700
 
479
-        log.info("Successfully saved outfile as '{}'".format(rv))
701
+        log.info("Saving picture as '{}'".format(args.outfile))
702
+
703
+        if type(pic) == io.StringIO:
704
+            openmode = "w"
705
+        else:
706
+            openmode = "wb"
707
+        with args.outfile.open(openmode) as f:
708
+            f.write(pic.read())
480 709
 
481 710
         return 0
482 711
 
483 712
 # -----------------------------------------------------------------------------
484 713
 def getTournamentTop(
485 714
         id_or_slug,
486
-        get_prefixes = True,
715
+        event_slug = None,
716
+        import_options = [],
487 717
         top = 8,
488 718
         token = "",
489 719
         proxy = None,
490
-        log=LOG_DUMMY):
720
+        log=LOG_DUMMY,
721
+        ):
491 722
     """Returns a tuple : the smashgg.Tournament object and a list of the top
492 723
     smashgg.Player in that tournament."""
493 724
 
@@ -537,6 +768,36 @@ def getTournamentTop(
537 768
         return event
538 769
 
539 770
     # -------------------------------------------------------------------------
771
+    # Select the specified event
772
+    def selectEventBySlug(data, slug, log=LOG_DUMMY):
773
+
774
+        try:
775
+            event = data["events"][0]
776
+        except:
777
+            log.error("No event found in data")
778
+            log.debug(data)
779
+            return None
780
+
781
+        for e in data["events"]:
782
+            try:
783
+                slug_full = e["slug"]
784
+            except KeyError:
785
+                continue
786
+
787
+            if (    slug == slug_full
788
+                 or slug == slug_full.split("/")[-1] ):
789
+                log.info("Selected Event '{}' by slug '{}'" \
790
+                        .format(
791
+                            e["name"],
792
+                            slug,
793
+                            ))
794
+                return e
795
+
796
+
797
+        log.error("No Event matching slug '{}' found".format(slug))
798
+        return None
799
+
800
+    # -------------------------------------------------------------------------
540 801
     data = None
541 802
 
542 803
     try:
@@ -575,7 +836,11 @@ def getTournamentTop(
575 836
         log.error("Failed to load Tournament")
576 837
         return None,None
577 838
 
578
-    event = selectBiggestEvent(tournament_data, log)
839
+    event = None
840
+    if event_slug is None:
841
+        event = selectBiggestEvent(tournament_data, log)
842
+    else:
843
+        event = selectEventBySlug(tournament_data, event_slug, log)
579 844
 
580 845
     if event is None :
581 846
         return None,None
@@ -584,6 +849,7 @@ def getTournamentTop(
584 849
     tournament = smashgg.Tournament(
585 850
             id = tournament_data["id"],
586 851
             slug = tournament_data["slug"],
852
+            game = event["videogame"],
587 853
             name = tournament_data["name"],
588 854
             startAt = \
589 855
                     datetime.datetime. \
@@ -594,7 +860,10 @@ def getTournamentTop(
594 860
             city = tournament_data["city"],
595 861
             countryCode = tournament_data["countryCode"],
596 862
             hashtag = tournament_data["hashtag"],
597
-            )
863
+            ) \
864
+                    .clean_name(
865
+                            import_options.get("name_seo_delimiter", None)
866
+                            )
598 867
 
599 868
 
600 869
     # Get the top players
@@ -605,10 +874,16 @@ def getTournamentTop(
605 874
     for standing in standings :
606 875
 
607 876
         seeding = None
877
+        seeding32 = None
608 878
         for seed in standing["entrant"]["seeds"]:
609 879
             # Take the seeding from the phase with *all* Event entrants
610 880
             if seed["phase"]["numSeeds"] == tournament.numEntrants:
611 881
                 seeding = seed["groupSeedNum"]
882
+            if seed["phase"]["numSeeds"] == 32:
883
+                seeding32 = seed["groupSeedNum"]
884
+        if seeding is None:
885
+            log.info("no global seeding found, using top 32 seeding")
886
+            seeding = seeding32
612 887
 
613 888
         participant_data = standing["entrant"]["participants"][0]
614 889
 
@@ -619,10 +894,10 @@ def getTournamentTop(
619 894
                     ["authorizations"] \
620 895
                     [0] \
621 896
                     ["externalUsername"]
622
-        except TypeError:
897
+        except:
623 898
             twitterHandle = None
624 899
 
625
-        if get_prefixes:
900
+        if "use_smashgg_prefixes" in import_options:
626 901
             prefix = participant_data["prefix"]
627 902
         else:
628 903
             prefix = ""
@@ -664,7 +939,11 @@ def getTournamentTop(
664 939
         log.error("Failed to load Tournament")
665 940
         return None,None
666 941
 
667
-    event = selectBiggestEvent(tournament_data, log)
942
+    event = None
943
+    if event_slug is None:
944
+        event = selectBiggestEvent(tournament_data, log)
945
+    else:
946
+        event = selectEventBySlug(tournament_data, event_slug, log)
668 947
 
669 948
     if event is None :
670 949
         return None,None
@@ -684,6 +963,7 @@ def getTournamentTop(
684 963
                         eid = slct["entrant"]["id"]
685 964
                         try:
686 965
                             top_players[eid].add_character_selection(
966
+                                    game = tournament.game,
687 967
                                     character = slct["selectionValue"],
688 968
                                     win = (winnerId == eid),
689 969
                                     )

+ 2 - 2
lokrez/challonge.py

@@ -4,7 +4,7 @@ import pathlib
4 4
 
5 5
 import requests
6 6
 
7
-from . import characters_ssbu
7
+from .games import ssbu
8 8
 
9 9
 # =============================================================================
10 10
 API_HOST = "api.challonge.com"
@@ -16,7 +16,7 @@ API_URL = "{scheme}://{host}/{endpoint}".format(
16 16
         endpoint = API_ENDPOINT,
17 17
         )
18 18
 
19
-CHARACTERS = { c.smashggid : c.name for c in characters_ssbu.EVERYONE }
19
+CHARACTERS = { c.smashggid : c.name for c in ssbu.EVERYONE }
20 20
 
21 21
 PLAYERSKINS = {}
22 22
 

+ 0 - 739
lokrez/characters_ssbu.py

@@ -1,739 +0,0 @@
1
-# -------------------------------------------------------------------------
2
-class SSBUCharacter:
3
-    """Infos needed about an SSBU character"""
4
-    def __init__(
5
-            self,
6
-            name,
7
-            codename,
8
-            spritersurls,
9
-            smashggid = None,
10
-            ):
11
-        self.spritersurls = spritersurls
12
-        self.smashggid = smashggid
13
-        self.name = name
14
-        self.codename = codename
15
-        
16
-# -------------------------------------------------------------------------
17
-EVERYONE = [
18
-        SSBUCharacter(
19
-            smashggid = 1530,
20
-            name = "banjo & kazooie",
21
-            codename = "buddy",
22
-            spritersurls = [
23
-                "https://www.spriters-resource.com/download/121027/",
24
-                ],
25
-            ),
26
-        SSBUCharacter(
27
-            smashggid = None,
28
-            name = "bayonetta",
29
-            codename = "bayonetta",
30
-            spritersurls = [
31
-                "https://www.spriters-resource.com/download/111299/",
32
-                ],
33
-            ),
34
-        SSBUCharacter(
35
-            smashggid = 1272,
36
-            name = "bowser jr",
37
-            codename = "koopajr",
38
-            spritersurls = [
39
-                "https://www.spriters-resource.com/download/111303/",
40
-                ],
41
-            ),
42
-        SSBUCharacter(
43
-            smashggid = 1273,
44
-            name = "bowser",
45
-            codename = "koopa",
46
-            spritersurls = [
47
-                "https://www.spriters-resource.com/download/111302/",
48
-                ],
49
-            ),
50
-        SSBUCharacter(
51
-            smashggid = 1539,
52
-            name = "byleth",
53
-            codename = "master",
54
-            spritersurls = [
55
-                "https://www.spriters-resource.com/download/125348/",
56
-                ],
57
-            ),
58
-        SSBUCharacter(
59
-            smashggid = 1274,
60
-            name = "captain falcon",
61
-            codename = "captain",
62
-            spritersurls = [
63
-                "https://www.spriters-resource.com/download/111304/"
64
-                ],
65
-            ),
66
-        SSBUCharacter(
67
-                smashggid = None,
68
-                name = "charizard",
69
-                codename = "plizardon",
70
-                spritersurls = [
71
-                    "https://www.spriters-resource.com/download/111351/",
72
-                    ],
73
-                ),
74
-        SSBUCharacter(
75
-                smashggid = 1409,
76
-                name = "chrom",
77
-                codename = "chrom",
78
-                spritersurls = [
79
-                    "https://www.spriters-resource.com/download/111305/",
80
-                    ],
81
-                ),
82
-        SSBUCharacter(
83
-                smashggid = 1275,
84
-                name = "cloud",
85
-                codename = "cloud",
86
-                spritersurls = [
87
-                    "https://www.spriters-resource.com/download/111306/",
88
-                    ],
89
-                ),
90
-        SSBUCharacter(
91
-                smashggid = None,
92
-                name = "corrin",
93
-                codename = "kamui",
94
-                spritersurls = [
95
-                    "https://www.spriters-resource.com/download/111307/",
96
-                    ],
97
-                ),
98
-        SSBUCharacter(
99
-                smashggid = 1277,
100
-                name = "daisy",
101
-                codename = "daisy",
102
-                spritersurls = [
103
-                    "https://www.spriters-resource.com/download/111308/",
104
-                    ],
105
-                ),
106
-        SSBUCharacter(
107
-                smashggid = None,
108
-                name = "dark pit",
109
-                codename = "pitb",
110
-                spritersurls = [
111
-                    "https://www.spriters-resource.com/download/111309/",
112
-                    ],
113
-                ),
114
-        SSBUCharacter(
115
-                smashggid = 1279,
116
-                name = "diddy kong",
117
-                codename = "diddy",
118
-                spritersurls = [
119
-                    "https://www.spriters-resource.com/download/111311/",
120
-                    ],
121
-                ),
122
-        SSBUCharacter(
123
-                smashggid = 1280,
124
-                name = "donkey kong",
125
-                codename = "donkey",
126
-                spritersurls = [
127
-                    "https://www.spriters-resource.com/download/111312/",
128
-                    ],
129
-                ),
130
-        SSBUCharacter(
131
-                smashggid = 1282,
132
-                name = "dr mario",
133
-                codename = "mariod",
134
-                spritersurls = [
135
-                    "https://www.spriters-resource.com/download/111313/",
136
-                    ],
137
-                ),
138
-        SSBUCharacter(
139
-                smashggid = 1283,
140
-                name = "duck hunt",
141
-                codename = "duckhunt",
142
-                spritersurls = [
143
-                    "https://www.spriters-resource.com/download/111314/",
144
-                    ],
145
-                ),
146
-        SSBUCharacter(
147
-                smashggid = 1285,
148
-                name = "falco",
149
-                codename = "falco",
150
-                spritersurls = [
151
-                    "https://www.spriters-resource.com/download/111315/",
152
-                    ],
153
-                ),
154
-        SSBUCharacter(
155
-                smashggid = 1286,
156
-                name = "fox",
157
-                codename = "fox",
158
-                spritersurls = [
159
-                    "https://www.spriters-resource.com/download/111316/",
160
-                    ],
161
-                ),
162
-        SSBUCharacter(
163
-                smashggid = 1287,
164
-                name = "ganondorf",
165
-                codename = "ganon",
166
-                spritersurls = [
167
-                    "https://www.spriters-resource.com/download/111317/",
168
-                    ],
169
-                ),
170
-        SSBUCharacter(
171
-                smashggid = None,
172
-                name = "greninja",
173
-                codename = "gekkouga",
174
-                spritersurls = [
175
-                    "https://www.spriters-resource.com/download/111318/",
176
-                    ],
177
-                ),
178
-        SSBUCharacter(
179
-                smashggid = 1526,
180
-                name = "hero",
181
-                codename = "brave",
182
-                spritersurls = [
183
-                    "https://www.spriters-resource.com/download/119842/",
184
-                    ],
185
-                ),
186
-        SSBUCharacter(
187
-                smashggid = 1290,
188
-                name = "ice climbers",
189
-                codename = "ice_climber",
190
-                spritersurls = [
191
-                    "https://www.spriters-resource.com/download/111319/",
192
-                    ],
193
-                ),
194
-        SSBUCharacter(
195
-                smashggid = 1291,
196
-                name = "ike",
197
-                codename = "ike",
198
-                spritersurls = [
199
-                    "https://www.spriters-resource.com/download/111320/",
200
-                    ],
201
-                ),
202
-        SSBUCharacter(
203
-                smashggid = 1292,
204
-                name = "inkling",
205
-                codename = "inkling",
206
-                spritersurls = [
207
-                    "https://www.spriters-resource.com/download/111322/",
208
-                    ],
209
-                ),
210
-        SSBUCharacter(
211
-                smashggid = None,
212
-                name = "ivysaur",
213
-                codename = "pfushigisou",
214
-                spritersurls = [
215
-                    "https://www.spriters-resource.com/download/111352/",
216
-                    ],
217
-                ),
218
-        SSBUCharacter(
219
-                smashggid = 1293,
220
-                name = "jigglypuff",
221
-                codename = "purin",
222
-                spritersurls = [
223
-                    "https://www.spriters-resource.com/download/111324/",
224
-                    ],
225
-                ),
226
-        SSBUCharacter(
227
-                smashggid = 1410,
228
-                name = "ken",
229
-                codename = "ken",
230
-                spritersurls = [
231
-                    "https://www.spriters-resource.com/download/111325/",
232
-                    ],
233
-                ),
234
-        SSBUCharacter(
235
-                smashggid = 1294,
236
-                name = "king dedede",
237
-                codename = "dedede",
238
-                spritersurls = [
239
-                    "https://www.spriters-resource.com/download/111326/",
240
-                    ],
241
-                ),
242
-        SSBUCharacter(
243
-                smashggid = 1295,
244
-                name = "kirby",
245
-                codename = "kirby",
246
-                spritersurls = [
247
-                    "https://www.spriters-resource.com/download/111328/",
248
-                    ],
249
-                ),
250
-        SSBUCharacter(
251
-                smashggid = 1296,
252
-                name = "link",
253
-                codename = "link",
254
-                spritersurls = [
255
-                    "https://www.spriters-resource.com/download/111329/",
256
-                    ],
257
-                ),
258
-        SSBUCharacter(
259
-                smashggid = 1297,
260
-                name = "little mac",
261
-                codename = "littlemac",
262
-                spritersurls = [
263
-                    "https://www.spriters-resource.com/download/111330/",
264
-                    ],
265
-                ),
266
-        SSBUCharacter(
267
-                smashggid = 1298,
268
-                name = "lucario",
269
-                codename = "lucario",
270
-                spritersurls = [
271
-                    "https://www.spriters-resource.com/download/111331/",
272
-                    ],
273
-                ),
274
-        SSBUCharacter(
275
-                smashggid = 1299,
276
-                name = "lucas",
277
-                codename = "lucas",
278
-                spritersurls = [
279
-                    "https://www.spriters-resource.com/download/111332/",
280
-                    ],
281
-                ),
282
-        SSBUCharacter(
283
-                smashggid = 1300,
284
-                name = "lucina",
285
-                codename = "lucina",
286
-                spritersurls = [
287
-                    "https://www.spriters-resource.com/download/111333/",
288
-                    ],
289
-                ),
290
-        SSBUCharacter(
291
-                smashggid = 1301,
292
-                name = "luigi",
293
-                codename = "luigi",
294
-                spritersurls = [
295
-                    "https://www.spriters-resource.com/download/111334/",
296
-                    ],
297
-                ),
298
-        SSBUCharacter(
299
-                smashggid = 1302,
300
-                name = "mario",
301
-                codename = "mario",
302
-                spritersurls = [
303
-                    "https://www.spriters-resource.com/download/111335/",
304
-                    ],
305
-                ),
306
-        SSBUCharacter(
307
-                smashggid = None,
308
-                name = "marth",
309
-                codename = "marth",
310
-                spritersurls = [
311
-                    "https://www.spriters-resource.com/download/111336/",
312
-                    ],
313
-                ),
314
-        SSBUCharacter(
315
-                smashggid = 1305,
316
-                name = "mega man",
317
-                codename = "rockman",
318
-                spritersurls = [
319
-                    "https://www.spriters-resource.com/download/111337/",
320
-                    ],
321
-                ),
322
-        SSBUCharacter(
323
-                smashggid = 1307,
324
-                name = "meta knight",
325
-                codename = "metaknight",
326
-                spritersurls = [
327
-                    "https://www.spriters-resource.com/download/111338/",
328
-                    ],
329
-                ),
330
-        SSBUCharacter(
331
-                smashggid = 1310,
332
-                name = "mewtwo",
333
-                codename = "mewtwo",
334
-                spritersurls = [
335
-                    "https://www.spriters-resource.com/download/111339/",
336
-                    ],
337
-                ),
338
-        SSBUCharacter(
339
-                smashggid = None,
340
-                name = "mii fighter",
341
-                codename = "miifighter",
342
-                spritersurls = [
343
-                    "https://www.spriters-resource.com/download/111340/",
344
-                    ],
345
-                ),
346
-        SSBUCharacter(
347
-                smashggid = 1415,
348
-                name = "mii gunner",
349
-                codename = "miigunner",
350
-                spritersurls = [
351
-                    "https://www.spriters-resource.com/download/111340/",
352
-                    ],
353
-                ),
354
-        SSBUCharacter(
355
-                smashggid = None,
356
-                name = "mii swordsman",
357
-                codename = "miiswordsman",
358
-                spritersurls = [
359
-                    "https://www.spriters-resource.com/download/111340/",
360
-                    ],
361
-                ),
362
-        SSBUCharacter(
363
-                smashggid = 1313,
364
-                name = "ness",
365
-                codename = "ness",
366
-                spritersurls = [
367
-                    "https://www.spriters-resource.com/download/111342/",
368
-                    ],
369
-                ),
370
-        SSBUCharacter(
371
-                smashggid = 1314,
372
-                name = "olimar",
373
-                codename = "pikmin",
374
-                spritersurls = [
375
-                    "https://www.spriters-resource.com/download/111343/",
376
-                    ],
377
-                ),
378
-        SSBUCharacter(
379
-                smashggid = 1315,
380
-                name = "pacman",
381
-                codename = "pacman",
382
-                spritersurls = [
383
-                    "https://www.spriters-resource.com/download/111344/",
384
-                    ],
385
-                ),
386
-        SSBUCharacter(
387
-                smashggid = 1316,
388
-                name = "palutena",
389
-                codename = "palutena",
390
-                spritersurls = [
391
-                    "https://www.spriters-resource.com/download/111345/",
392
-                    ],
393
-                ),
394
-        SSBUCharacter(
395
-                smashggid = 1317,
396
-                name = "peach",
397
-                codename = "peach",
398
-                spritersurls = [
399
-                    "https://www.spriters-resource.com/download/111346/",
400
-                    ],
401
-                ),
402
-        SSBUCharacter(
403
-                smashggid = 1318,
404
-                name = "pichu",
405
-                codename = "pichu",
406
-                spritersurls = [
407
-                    "https://www.spriters-resource.com/download/111347/",
408
-                    ],
409
-                ),
410
-        SSBUCharacter(
411
-                smashggid = 1319,
412
-                name = "pikachu",
413
-                codename = "pikachu",
414
-                spritersurls = [
415
-                    "https://www.spriters-resource.com/download/111348/",
416
-                    ],
417
-                ),
418
-        SSBUCharacter(
419
-                smashggid = 1320,
420
-                name = "pit",
421
-                codename = "pit",
422
-                spritersurls = [
423
-                    "https://www.spriters-resource.com/download/111349/",
424
-                    ],
425
-                ),
426
-        SSBUCharacter(
427
-                smashggid = 1321,
428
-                name = "pokemon trainer",
429
-                codename = "ptrainer",
430
-                spritersurls = [
431
-                    "https://www.spriters-resource.com/download/111350/",
432
-                    ],
433
-                ),
434
-        SSBUCharacter(
435
-                smashggid = 1412,
436
-                name = "richter",
437
-                codename = "richter",
438
-                spritersurls = [
439
-                    "https://www.spriters-resource.com/download/111354/",
440
-                    ],
441
-                ),
442
-        SSBUCharacter(
443
-                smashggid = 1322,
444
-                name = "ridley",
445
-                codename = "ridley",
446
-                spritersurls = [
447
-                    "https://www.spriters-resource.com/download/111355/",
448
-                    ],
449
-                ),
450
-        SSBUCharacter(
451
-                smashggid = 1323,
452
-                name = "rob",
453
-                codename = "robot",
454
-                spritersurls = [
455
-                    "https://www.spriters-resource.com/download/111356/",
456
-                    ],
457
-                ),
458
-        SSBUCharacter(
459
-                smashggid = 1324,
460
-                name = "robin",
461
-                codename = "reflet",
462
-                spritersurls = [
463
-                    "https://www.spriters-resource.com/download/111357/",
464
-                    ],
465
-                ),
466
-        SSBUCharacter(
467
-                smashggid = 1325,
468
-                name = "rosalina and luma",
469
-                codename = "rosetta",
470
-                spritersurls = [
471
-                    "https://www.spriters-resource.com/download/111358/",
472
-                    ],
473
-                ),
474
-        SSBUCharacter(
475
-                smashggid = 1326,
476
-                name = "roy",
477
-                codename = "roy",
478
-                spritersurls = [
479
-                    "https://www.spriters-resource.com/download/111359/",
480
-                    ],
481
-                ),
482
-        SSBUCharacter(
483
-                smashggid = 1327,
484
-                name = "ryu",
485
-                codename = "ryu",
486
-                spritersurls = [
487
-                    "https://www.spriters-resource.com/download/111360/",
488
-                    ],
489
-                ),
490
-        SSBUCharacter(
491
-                smashggid = 1328,
492
-                name = "samus",
493
-                codename = "samus",
494
-                spritersurls = [
495
-                    "https://www.spriters-resource.com/download/111361/",
496
-                    ],
497
-                ),
498
-        SSBUCharacter(
499
-                smashggid = 1329,
500
-                name = "sheik",
501
-                codename = "sheik",
502
-                spritersurls = [
503
-                    "https://www.spriters-resource.com/download/111362/",
504
-                    ],
505
-                ),
506
-        SSBUCharacter(
507
-                smashggid = 1330,
508
-                name = "shulk",
509
-                codename = "shulk",
510
-                spritersurls = [
511
-                    "https://www.spriters-resource.com/download/111363/",
512
-                    ],
513
-                ),
514
-        SSBUCharacter(
515
-                smashggid = None,
516
-                name = "simon",
517
-                codename = "simon",
518
-                spritersurls = [
519
-                    "https://www.spriters-resource.com/download/111364/",
520
-                    ],
521
-                ),
522
-        SSBUCharacter(
523
-                smashggid = 1331,
524
-                name = "snake",
525
-                codename = "snake",
526
-                spritersurls = [
527
-                    "https://www.spriters-resource.com/download/111365/",
528
-                    ],
529
-                ),
530
-        SSBUCharacter(
531
-                smashggid = 1332,
532
-                name = "sonic",
533
-                codename = "sonic",
534
-                spritersurls = [
535
-                    "https://www.spriters-resource.com/download/111366/",
536
-                    ],
537
-                ),
538
-        SSBUCharacter(
539
-                smashggid = None,
540
-                name = "squirtle",
541
-                codename = "pzenigame",
542
-                spritersurls = [
543
-                    "https://www.spriters-resource.com/download/111353/",
544
-                    ],
545
-                ),
546
-        SSBUCharacter(
547
-                smashggid = 1333,
548
-                name = "toon link",
549
-                codename = "toonlink",
550
-                spritersurls = [
551
-                    "https://www.spriters-resource.com/download/111367/",
552
-                    ],
553
-                ),
554
-        SSBUCharacter(
555
-                smashggid = 1334,
556
-                name = "villager",
557
-                codename = "murabito",
558
-                spritersurls = [
559
-                    "https://www.spriters-resource.com/download/111368/",
560
-                    ],
561
-                ),
562
-        SSBUCharacter(
563
-                smashggid = 1335,
564
-                name = "wario",
565
-                codename = "wario",
566
-                spritersurls = [
567
-                    "https://www.spriters-resource.com/download/111369/",
568
-                    ],
569
-                ),
570
-        SSBUCharacter(
571
-                smashggid = 1336,
572
-                name = "wii fit trainer",
573
-                codename = "wiifit",
574
-                spritersurls = [
575
-                    "https://www.spriters-resource.com/download/111370/",
576
-                    ],
577
-                ),
578
-        SSBUCharacter(
579
-                smashggid = 1337,
580
-                name = "wolf",
581
-                codename = "wolf",
582
-                spritersurls = [
583
-                    "https://www.spriters-resource.com/download/111371/",
584
-                    ],
585
-                ),
586
-        SSBUCharacter(
587
-                smashggid = 1338,
588
-                name = "yoshi",
589
-                codename = "yoshi",
590
-                spritersurls = [
591
-                    "https://www.spriters-resource.com/download/111372/",
592
-                    ],
593
-                ),
594
-        SSBUCharacter(
595
-                smashggid = 1339,
596
-                name = "young link",
597
-                codename = "younglink",
598
-                spritersurls = [
599
-                    "https://www.spriters-resource.com/download/111373/",
600
-                    ],
601
-                ),
602
-        SSBUCharacter(
603
-                smashggid = 1340,
604
-                name = "zelda",
605
-                codename = "zelda",
606
-                spritersurls = [
607
-                    "https://www.spriters-resource.com/download/111374/",
608
-                    ],
609
-                ),
610
-        SSBUCharacter(
611
-                smashggid = 1341,
612
-                name = "zero suit samus",
613
-                codename = "szerosuit",
614
-                spritersurls = [
615
-                    "https://www.spriters-resource.com/download/111375/",
616
-                    ],
617
-                ),
618
-        SSBUCharacter(
619
-                smashggid = 1405,
620
-                name = "mr game and watch",
621
-                codename = "gamewatch",
622
-                spritersurls = [
623
-                    "https://www.spriters-resource.com/download/111341/",
624
-                    ],
625
-                ),
626
-        SSBUCharacter(
627
-                smashggid = 1406,
628
-                name = "incineroar",
629
-                codename = "gaogaen",
630
-                spritersurls = [
631
-                    "https://www.spriters-resource.com/download/111321/",
632
-                    ],
633
-                ),
634
-        SSBUCharacter(
635
-                smashggid = 1407,
636
-                name = "king k rool",
637
-                codename = "krool",
638
-                spritersurls = [
639
-                    "https://www.spriters-resource.com/download/111327/",
640
-                    ],
641
-                ),
642
-        SSBUCharacter(
643
-                smashggid = 1408,
644
-                name = "dark samus",
645
-                codename = "samusd",
646
-                spritersurls = [
647
-                    "https://www.spriters-resource.com/download/111310/",
648
-                    ],
649
-                ),
650
-        SSBUCharacter(
651
-                smashggid = 1413,
652
-                name = "isabelle",
653
-                codename = "shizue",
654
-                spritersurls = [
655
-                    "https://www.spriters-resource.com/download/111323/",
656
-                    ],
657
-                ),
658
-        SSBUCharacter(
659
-                smashggid = 1441,
660
-                name = "piranha plant",
661
-                codename = "packun",
662
-                spritersurls = [
663
-                    "https://www.spriters-resource.com/download/113440/",
664
-                    ],
665
-                ),
666
-        SSBUCharacter(
667
-                smashggid = 1453,
668
-                name = "joker",
669
-                codename = "jack",
670
-                spritersurls = [
671
-                    "https://www.spriters-resource.com/download/116168/",
672
-                    ],
673
-                ),
674
-        SSBUCharacter(
675
-                smashggid = 1532,
676
-                name = "terry",
677
-                codename = "dolly",
678
-                spritersurls = [
679
-                    "https://www.spriters-resource.com/download/123089/",
680
-                    ],
681
-                ),
682
-        SSBUCharacter(
683
-                smashggid = 1747,
684
-                name = "min min",
685
-                codename = "tantan",
686
-                spritersurls = [
687
-                    "https://www.spriters-resource.com/download/134242/",
688
-                    ],
689
-                ),
690
-        SSBUCharacter(
691
-                smashggid = 1766,
692
-                name = "steve",
693
-                codename = "pickel",
694
-                spritersurls = [
695
-                    "https://www.spriters-resource.com/download/140939/",
696
-                    ],
697
-                ),
698
-        SSBUCharacter(
699
-                smashggid = 1777,
700
-                name = "sephiroth",
701
-                codename = "edge",
702
-                spritersurls = [
703
-                    "https://www.spriters-resource.com/download/145102/",
704
-                    ],
705
-                ),
706
-        SSBUCharacter(
707
-                smashggid = None,
708
-                name = "pyra",
709
-                codename = "eflame_only",
710
-                spritersurls = [
711
-                    "https://www.spriters-resource.com/download/149626/",
712
-                    ],
713
-                ),
714
-        SSBUCharacter(
715
-                smashggid = None,
716
-                name = "pyra & mythra",
717
-                codename = "eflame_first",
718
-                spritersurls = [
719
-                    "https://www.spriters-resource.com/download/149627/",
720
-                    ],
721
-                ),
722
-        SSBUCharacter(
723
-                smashggid = None,
724
-                name = "mythra",
725
-                codename = "elight_only",
726
-                spritersurls = [
727
-                    "https://www.spriters-resource.com/download/149628/",
728
-                    ],
729
-                ),
730
-        SSBUCharacter(
731
-                smashggid = None,
732
-                name = "mythra & pyra",
733
-                codename = "elight_first",
734
-                spritersurls = [
735
-                    "https://www.spriters-resource.com/download/149629/",
736
-                    ],
737
-                ),
738
-        ]
739
-

+ 0 - 173
lokrez/export.py

@@ -9,179 +9,6 @@ import urllib
9 9
 import jinja2
10 10
 
11 11
 # =============================================================================
12
-def generate_outfile(
13
-        templatesdir,
14
-        templatename,
15
-        context,
16
-        outfilename,
17
-        log = None,
18
-        cachedir = None,
19
-        options = {},
20
-        ):
21
-
22
-    # Template rendering
23
-    # -------------------------------------------------------------------------
24
-    log.info("Generating SVG using '{}' template".format(templatename))
25
-    log.debug("Context : {}".format(context))
26
-    log.debug("Options : {}".format(options))
27
-
28
-    log.debug(
29
-            "Initializing jinja2 with template dir '{}'" \
30
-                    .format(templatesdir)
31
-                    )
32
-    jj2_env = jinja2.Environment(
33
-            loader = jinja2.FileSystemLoader(
34
-                str(templatesdir),
35
-                )
36
-            )
37
-
38
-    try:
39
-        jj2_tpl = jj2_env.get_template(
40
-                # Jinja specific path format
41
-                "{}/template.svg.j2".format(templatename),
42
-                )
43
-    except Exception as e:
44
-        log.error("Could not find template '{}'".format(templatename))
45
-        log.debug(e, exc_info=1)
46
-        return None
47
-
48
-    # To SVG
49
-    # -------------------------------------------------------------------------
50
-    if outfilename.suffix == ".svg":
51
-
52
-        if options.get("svg_embed_png", False):
53
-            log.debug("embedding png images")
54
-
55
-            with open(outfilename, "w") as out:
56
-                for line in jj2_tpl.render(context).splitlines():
57
-                    l = line.strip()
58
-
59
-                    if (     l.startswith("xlink:href=\"file://")
60
-                         and l.endswith(".png\"") ):
61
-                        l = html.parser.unescape(l)
62
-                        image_url = urllib.parse.urlparse(
63
-                                "=".join( l.split("=")[1:] )[1:-1],
64
-                                )
65
-                        log.debug("embedding image '{}'".format(image_url.path))
66
-                        with open(image_url.path, "rb") as image:
67
-                            line = "xlink:href=\"data:image/png;base64,{d}\"" \
68
-                                    .format(
69
-                                            d = base64 \
70
-                                                    .b64encode(image.read()) \
71
-                                                    .decode("ascii"),
72
-                                                    )
73
-
74
-                    out.write(line)
75
-                    out.write("\n")
76
-
77
-        else:
78
-            jj2_tpl.stream(context).dump( str(outfilename) )
79
-
80
-        return outfilename
81
-
82
-    # To PNG with inkscape
83
-    # -------------------------------------------------------------------------
84
-    if outfilename.suffix == ".png":
85
-
86
-        cachedir.mkdir(parents=True, exist_ok=True)
87
-
88
-        tmpsvg = tempfile.NamedTemporaryFile(
89
-                suffix=".svg",
90
-                mode = "w",
91
-                delete = False,
92
-                dir = str(cachedir),
93
-                )
94
-        tmpsvg.close()
95
-        try:
96
-            log.info(
97
-                    "Exporting to {} using inkscape" \
98
-                            .format(outfilename.suffix),
99
-                            )
100
-            import subprocess
101
-
102
-            jj2_tpl.stream(context).dump( tmpsvg.name )
103
-
104
-            inkscape_process = subprocess.Popen(
105
-                    [
106
-                        "inkscape",
107
-                        tmpsvg.name,
108
-                        "--export-filename",
109
-                        str(outfilename),
110
-                        ],
111
-                    stdout = subprocess.PIPE,
112
-                    stderr = subprocess.STDOUT,
113
-                    universal_newlines = True,
114
-                    )
115
-
116
-            for line_out in iter(inkscape_process.stdout.readline, ""):
117
-                log.debug(line_out)
118
-
119
-            inkscape_process.stdout.close()
120
-
121
-            rv = inkscape_process.wait()
122
-
123
-            if rv != 0:
124
-                raise Exception(
125
-                        "Bad inkscape return code '{}'" \
126
-                                .format(inkscape_process.returncode)
127
-                                )
128
-
129
-
130
-            return outfilename
131
-
132
-        except Exception as e:
133
-            log.warning("Failed to export with inkscape")
134
-            log.debug(e, exc_info=True)
135
-
136
-        finally:
137
-            os.unlink(tmpsvg.name)
138
-
139
-    # To png, pdf or ps with cairosvg
140
-    # -------------------------------------------------------------------------
141
-    if outfilename.suffix in [ ".png", ".pdf", ".ps" ]:
142
-
143
-        log.info("Exporting to {} using cairosvg".format(outfilename.suffix))
144
-
145
-        try:
146
-            import cairosvg
147
-        except ImportError as e:
148
-            log.error(
149
-                    "Failed to export to '{}' with cairosvg" \
150
-                            .format(
151
-                                outfilename,
152
-                                )
153
-                            )
154
-            log.debug(e)
155
-
156
-        else:
157
-            svg_str = jj2_tpl.render(context)
158
-
159
-            if outfilename.suffix == ".png":
160
-                conversion_fun = cairosvg.svg2png
161
-            elif outfilename.suffix == ".pdf":
162
-                conversion_fun = cairosvg.svg2pdf
163
-            elif outfilename.suffix == ".ps":
164
-                conversion_fun = cairosvg.svg2ps
165
-
166
-            conversion_fun(
167
-                bytestring = svg_str,
168
-                write_to = str(outfilename),
169
-                )
170
-
171
-            return outfilename
172
-
173
-    # To unsupported format
174
-    # -------------------------------------------------------------------------
175
-    log.error(
176
-            "Can't export to '{}' : unsupported format '{}'" \
177
-                    .format(
178
-                        outfilename,
179
-                        outfilename.suffix,
180
-                        )
181
-                    )
182
-    return None
183
-
184
-# =============================================================================
185 12
 def generate_pic(
186 13
         templatesdir,
187 14
         templatename,

+ 39 - 0
lokrez/games/__init__.py

@@ -0,0 +1,39 @@
1
+# =============================================================================
2
+# -----------------------------------------------------------------------------
3
+class Character:
4
+    """Infos needed about a Smash character"""
5
+    def __init__(
6
+            self,
7
+            name,
8
+            codenames,
9
+            smashggid = None,
10
+            res_urls = {},
11
+            ):
12
+        self.res_urls = res_urls
13
+        self.smashggid = smashggid
14
+        self.name = name
15
+        self.codenames = codenames
16
+
17
+    def __str__(self):
18
+        return self.name
19
+
20
+# -----------------------------------------------------------------------------
21
+class Game:
22
+    def __init__(
23
+            self,
24
+            name,
25
+            fullname,
26
+            aliases,
27
+            smashggid = None,
28
+            ):
29
+
30
+        self.name = name
31
+        self.fullname = fullname
32
+        self.aliases = aliases
33
+        self.smashggid = smashggid
34
+
35
+    def list_names(self):
36
+        return [self.name] + [self.fullname] + self.aliases
37
+    
38
+    def __str__(self):
39
+        return self.name

+ 277 - 0
lokrez/games/melee.py

@@ -0,0 +1,277 @@
1
+from . import Character,Game
2
+
3
+# -----------------------------------------------------------------------------
4
+GAME = Game(
5
+        name = "melee",
6
+        fullname = "Super Smash Brothers Melee",
7
+        aliases = [
8
+            "ssbm",
9
+            "Super Smash Bros. Melee",
10
+            ],
11
+        smashggid = 1,
12
+        )
13
+        
14
+# -----------------------------------------------------------------------------
15
+EVERYONE = [
16
+        Character(
17
+            smashggid = 1,
18
+            name = "bowser",
19
+            codenames = [ "bowser", ],
20
+            res_urls = {
21
+                "smashlyon": [
22
+                        "https://resources.smashlyon.com/melee/bowser.zip",
23
+                        ],
24
+                },
25
+            ),
26
+        Character(
27
+            smashggid = 2,
28
+            name = "captain falcon",
29
+            codenames = [ "captain", ],
30
+            res_urls = {
31
+                "smashlyon": [
32
+                        "https://resources.smashlyon.com/melee/captain.zip",
33
+                        ]
34
+                },
35
+            ),
36
+        Character(
37
+                smashggid = 3,
38
+                name = "donkey kong",
39
+                codenames = [ "donkey", ],
40
+                res_urls = {
41
+                    "smashlyon": [
42
+                        "https://resources.smashlyon.com/melee/donkey.zip",
43
+                        ],
44
+                    },
45
+                ),
46
+        Character(
47
+                smashggid = 4,
48
+                name = "dr mario",
49
+                codenames = [ "dr", "doc", ],
50
+                res_urls = {
51
+                    "smashlyon": [
52
+                        "https://resources.smashlyon.com/melee/dr.zip",
53
+                        ],
54
+                    },
55
+                ),
56
+        Character(
57
+                smashggid = 5,
58
+                name = "falco",
59
+                codenames = [ "falco", ],
60
+                res_urls = {
61
+                    "smashlyon": [
62
+                        "https://resources.smashlyon.com/melee/falco.zip",
63
+                        ],
64
+                    },
65
+                ),
66
+        Character(
67
+                smashggid = 6,
68
+                name = "fox",
69
+                codenames = [ "fox", ],
70
+                res_urls = {
71
+                    "smashlyon": [
72
+                        "https://resources.smashlyon.com/melee/fox.zip",
73
+                        ],
74
+                    },
75
+                ),
76
+        Character(
77
+                smashggid = 7,
78
+                name = "ganondorf",
79
+                codenames = [ "ganondorf", ],
80
+                res_urls = {
81
+                    "smashlyon": [
82
+                        "https://resources.smashlyon.com/melee/ganondorf.zip",
83
+                        ],
84
+                    },
85
+                ),
86
+        Character(
87
+                smashggid = 8,
88
+                name = "ice climbers",
89
+                codenames = [ "ice", "iceclimber", ],
90
+                res_urls = {
91
+                    "smashlyon": [
92
+                        "https://resources.smashlyon.com/melee/ice.zip",
93
+                        ],
94
+                    },
95
+                ),
96
+        Character(
97
+                smashggid = 9,
98
+                name = "jigglypuff",
99
+                codenames = [ "jigglypuff", ],
100
+                res_urls = {
101
+                    "smashlyon": [
102
+                        "https://resources.smashlyon.com/melee/jigglypuff.zip",
103
+                        ],
104
+                    },
105
+                ),
106
+        Character(
107
+                smashggid = 10,
108
+                name = "kirby",
109
+                codenames = [ "kirby", ],
110
+                res_urls = {
111
+                    "smashlyon": [
112
+                        "https://resources.smashlyon.com/melee/kirby.zip",
113
+                        ],
114
+                    },
115
+                ),
116
+        Character(
117
+                smashggid = 11,
118
+                name = "link",
119
+                codenames = [ "link", ],
120
+                res_urls = {
121
+                    "smashlyon": [
122
+                        "https://resources.smashlyon.com/melee/link.zip",
123
+                        ],
124
+                    },
125
+                ),
126
+        Character(
127
+                smashggid = 12,
128
+                name = "luigi",
129
+                codenames = [ "luigi", ],
130
+                res_urls = {
131
+                    "smashlyon": [
132
+                        "https://resources.smashlyon.com/melee/luigi.zip",
133
+                        ],
134
+                    },
135
+                ),
136
+        Character(
137
+                smashggid = 13,
138
+                name = "mario",
139
+                codenames = [ "mario", ],
140
+                res_urls = {
141
+                    "smashlyon": [
142
+                        "https://resources.smashlyon.com/melee/mario.zip",
143
+                        ],
144
+                    },
145
+                ),
146
+        Character(
147
+                smashggid = 14,
148
+                name = "marth",
149
+                codenames = [ "marth", ],
150
+                res_urls = {
151
+                    "smashlyon": [
152
+                        "https://resources.smashlyon.com/melee/marth.zip",
153
+                        ],
154
+                    },
155
+                ),
156
+        Character(
157
+                smashggid = 15,
158
+                name = "mewtwo",
159
+                codenames = [ "mewtwo", ],
160
+                res_urls = {
161
+                    "smashlyon": [
162
+                        "https://resources.smashlyon.com/melee/mewtwo.zip",
163
+                        ],
164
+                    },
165
+                ),
166
+        Character(
167
+                smashggid = 16,
168
+                name = "mr game and watch",
169
+                codenames = [ "game", "mrgameandwatch", ],
170
+                res_urls = {
171
+                    "smashlyon": [
172
+                        "https://resources.smashlyon.com/melee/game.zip",
173
+                        ],
174
+                    },
175
+                ),
176
+        Character(
177
+                smashggid = 17,
178
+                name = "ness",
179
+                codenames = [ "ness", ],
180
+                res_urls = {
181
+                    "smashlyon": [
182
+                        "https://resources.smashlyon.com/melee/ness.zip",
183
+                        ],
184
+                    },
185
+                ),
186
+        Character(
187
+                smashggid = 18,
188
+                name = "peach",
189
+                codenames = [ "peach", ],
190
+                res_urls = {
191
+                    "smashlyon": [
192
+                        "https://resources.smashlyon.com/melee/peach.zip",
193
+                        ],
194
+                    },
195
+                ),
196
+        Character(
197
+                smashggid = 19,
198
+                name = "pichu",
199
+                codenames = [ "pichu", ],
200
+                res_urls = {
201
+                    "smashlyon": [
202
+                        "https://resources.smashlyon.com/melee/pichu.zip",
203
+                        ],
204
+                    },
205
+                ),
206
+        Character(
207
+                smashggid = 20,
208
+                name = "pikachu",
209
+                codenames = [ "pikachu", ],
210
+                res_urls = {
211
+                    "smashlyon": [
212
+                        "https://resources.smashlyon.com/melee/pikachu.zip",
213
+                        ],
214
+                    },
215
+                ),
216
+        Character(
217
+                smashggid = 21,
218
+                name = "roy",
219
+                codenames = [ "roy", ],
220
+                res_urls = {
221
+                    "smashlyon": [
222
+                        "https://resources.smashlyon.com/melee/roy.zip",
223
+                        ],
224
+                    },
225
+                ),
226
+        Character(
227
+                smashggid = 22,
228
+                name = "samus",
229
+                codenames = [ "samus", ],
230
+                res_urls = {
231
+                    "smashlyon": [
232
+                        "https://resources.smashlyon.com/melee/samus.zip",
233
+                        ],
234
+                    },
235
+                ),
236
+        Character(
237
+                smashggid = 23,
238
+                name = "sheik",
239
+                codenames = [ "sheik", ],
240
+                res_urls = {
241
+                    "smashlyon": [
242
+                        "https://resources.smashlyon.com/melee/sheik.zip",
243
+                        ],
244
+                    },
245
+                ),
246
+        Character(
247
+                smashggid = 24,
248
+                name = "yoshi",
249
+                codenames = [ "yoshi", ],
250
+                res_urls = {
251
+                    "smashlyon": [
252
+                        "https://resources.smashlyon.com/melee/yoshi.zip",
253
+                        ],
254
+                    },
255
+                ),
256
+        Character(
257
+                smashggid = 25,
258
+                name = "young link",
259
+                codenames = [ "young", "yink",  ],
260
+                res_urls = {
261
+                    "smashlyon": [
262
+                        "https://resources.smashlyon.com/melee/young.zip",
263
+                        ],
264
+                    },
265
+                ),
266
+        Character(
267
+                smashggid = 26,
268
+                name = "zelda",
269
+                codenames = [ "zelda", ],
270
+                res_urls = {
271
+                    "smashlyon": [
272
+                        "https://resources.smashlyon.com/melee/zelda.zip",
273
+                        ],
274
+                    },
275
+                ),
276
+        ]
277
+

+ 479 - 0
lokrez/games/pplus.py

@@ -0,0 +1,479 @@
1
+from . import Character,Game
2
+
3
+# -----------------------------------------------------------------------------
4
+GAME = Game(
5
+        name = "pplus",
6
+        fullname = "Project +",
7
+        aliases = [
8
+            "projectplus",
9
+            "p+",
10
+            "project plus",
11
+            "Project+",
12
+            ],
13
+        smashggid = 33602,
14
+        )
15
+        
16
+# -----------------------------------------------------------------------------
17
+EVERYONE = [
18
+        Character(
19
+            smashggid = 1586,
20
+            name = "bowser",
21
+            codenames = [ "Bowser", ],
22
+            res_urls = {
23
+                "smashlyon": [
24
+                        "https://resources.smashlyon.com/pplus/Bowser.zip",
25
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
26
+                        ],
27
+                },
28
+            ),
29
+        Character(
30
+            smashggid = 1610,
31
+            name = "captain falcon",
32
+            codenames = [ "CF", ],
33
+            res_urls = {
34
+                "smashlyon": [
35
+                        "https://resources.smashlyon.com/pplus/Captain Falcon.zip",
36
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
37
+                        ]
38
+                },
39
+            ),
40
+        Character(
41
+                smashggid = 1608,
42
+                name = "charizard",
43
+                codenames = [ "charizard", ],
44
+                res_urls = {
45
+                    "smashlyon": [
46
+                        "https://resources.smashlyon.com/pplus/Charizard.zip",
47
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
48
+                        ],
49
+                    },
50
+                ),
51
+        Character(
52
+                smashggid = 1589,
53
+                name = "diddy kong",
54
+                codenames = [ "Diddy", ],
55
+                res_urls = {
56
+                    "smashlyon": [
57
+                        "https://resources.smashlyon.com/pplus/Diddy Kong.zip",
58
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
59
+                        ],
60
+                    },
61
+                ),
62
+        Character(
63
+                smashggid = 1588,
64
+                name = "donkey kong",
65
+                codenames = [ "DK", ],
66
+                res_urls = {
67
+                    "smashlyon": [
68
+                        "https://resources.smashlyon.com/pplus/Donkey Kong.zip",
69
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
70
+                        ],
71
+                    },
72
+                ),
73
+        Character(
74
+                smashggid = 1601,
75
+                name = "falco",
76
+                codenames = [ "falco", ],
77
+                res_urls = {
78
+                    "smashlyon": [
79
+                        "https://resources.smashlyon.com/pplus/Falco.zip",
80
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
81
+                        ],
82
+                    },
83
+                ),
84
+        Character(
85
+                smashggid = 1600,
86
+                name = "fox",
87
+                codenames = [ "fox", ],
88
+                res_urls = {
89
+                    "smashlyon": [
90
+                        "https://resources.smashlyon.com/pplus/Fox.zip",
91
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
92
+                        ],
93
+                    },
94
+                ),
95
+        Character(
96
+                smashggid = 1593,
97
+                name = "Ganondorf",
98
+                codenames = [ "ganon", ],
99
+                res_urls = {
100
+                    "smashlyon": [
101
+                        "https://resources.smashlyon.com/pplus/Ganondorf.zip",
102
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
103
+                        ],
104
+                    },
105
+                ),
106
+        Character(
107
+                smashggid = 1613,
108
+                name = "ice climbers",
109
+                codenames = [ "IC", ],
110
+                res_urls = {
111
+                    "smashlyon": [
112
+                        "https://resources.smashlyon.com/pplus/Ice Climbers.zip",
113
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
114
+                        ],
115
+                    },
116
+                ),
117
+        Character(
118
+                smashggid = 1616,
119
+                name = "ike",
120
+                codenames = [ "Ike", ],
121
+                res_urls = {
122
+                    "smashlyon": [
123
+                        "https://resources.smashlyon.com/pplus/Ike.zip",
124
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
125
+                        ],
126
+                    },
127
+                ),
128
+        Character(
129
+                smashggid = 1607,
130
+                name = "ivysaur",
131
+                codenames = [ "Ivysaur", ],
132
+                res_urls = {
133
+                    "smashlyon": [
134
+                        "https://resources.smashlyon.com/pplus/Ivysaur.zip",
135
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
136
+                        ],
137
+                    },
138
+                ),
139
+        Character(
140
+                smashggid = 1604,
141
+                name = "jigglypuff",
142
+                codenames = [ "jigglypuff", ],
143
+                res_urls = {
144
+                    "smashlyon": [
145
+                        "https://resources.smashlyon.com/pplus/Jigglypuff.zip",
146
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
147
+                        ],
148
+                    },
149
+                ),
150
+        Character(
151
+                smashggid = 1599,
152
+                name = "king dedede",
153
+                codenames = [ "DeDeDe", ],
154
+                res_urls = {
155
+                    "smashlyon": [
156
+                        "https://resources.smashlyon.com/pplus/DeDeDe.zip",
157
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
158
+                        ],
159
+                    },
160
+                ),
161
+        Character(
162
+                smashggid = 1597,
163
+                name = "kirby",
164
+                codenames = [ "Kirby", ],
165
+                res_urls = {
166
+                    "smashlyon": [
167
+                        "https://resources.smashlyon.com/pplus/Kirby.zip",
168
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
169
+                        ],
170
+                    },
171
+                ),
172
+        Character(
173
+                smashggid = 1590,
174
+                name = "link",
175
+                codenames = [ "link", ],
176
+                res_urls = {
177
+                    "smashlyon": [
178
+                        "https://resources.smashlyon.com/pplus/Link.zip",
179
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
180
+                        ],
181
+                    },
182
+                ),
183
+        Character(
184
+                smashggid = 1609,
185
+                name = "lucario",
186
+                codenames = [ "Lucario", ],
187
+                res_urls = {
188
+                    "smashlyon": [
189
+                        "https://resources.smashlyon.com/pplus/Lucario.zip",
190
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
191
+                        ],
192
+                    },
193
+                ),
194
+        Character(
195
+                smashggid = 1612,
196
+                name = "lucas",
197
+                codenames = [ "lucas", ],
198
+                res_urls = {
199
+                    "smashlyon": [
200
+                        "https://resources.smashlyon.com/pplus/Lucas.zip",
201
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
202
+                        ],
203
+                    },
204
+                ),
205
+        Character(
206
+                smashggid = 1584,
207
+                name = "luigi",
208
+                codenames = [ "luigi", ],
209
+                res_urls = {
210
+                    "smashlyon": [
211
+                        "https://resources.smashlyon.com/pplus/Luigi.zip",
212
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
213
+                        ],
214
+                    },
215
+                ),
216
+        Character(
217
+                smashggid = 1583,
218
+                name = "mario",
219
+                codenames = [ "Mario", ],
220
+                res_urls = {
221
+                    "smashlyon": [
222
+                        "https://resources.smashlyon.com/pplus/Mario.zip",
223
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
224
+                        ],
225
+                    },
226
+                ),
227
+        Character(
228
+                smashggid = 1614,
229
+                name = "marth",
230
+                codenames = [ "Marth", ],
231
+                res_urls = {
232
+                    "smashlyon": [
233
+                        "https://resources.smashlyon.com/pplus/Marth.zip",
234
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
235
+                        ],
236
+                    },
237
+                ),
238
+        Character(
239
+                smashggid = 1598,
240
+                name = "meta knight",
241
+                codenames = [ "metaknight", ],
242
+                res_urls = {
243
+                    "smashlyon": [
244
+                        "https://resources.smashlyon.com/pplus/Metaknight.zip",
245
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
246
+                        ],
247
+                    },
248
+                ),
249
+        Character(
250
+                smashggid = 1605,
251
+                name = "mewtwo",
252
+                codenames = [ "mewtwo", ],
253
+                res_urls = {
254
+                    "smashlyon": [
255
+                        "https://resources.smashlyon.com/pplus/Mewtwo.zip",
256
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
257
+                        ],
258
+                    },
259
+                ),
260
+        Character(
261
+                smashggid = 1611,
262
+                name = "ness",
263
+                codenames = [ "ness", ],
264
+                res_urls = {
265
+                    "smashlyon": [
266
+                        "https://resources.smashlyon.com/pplus/Ness.zip",
267
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
268
+                        ],
269
+                    },
270
+                ),
271
+        Character(
272
+                smashggid = 1620,
273
+                name = "olimar",
274
+                codenames = [ "Olimar", ],
275
+                res_urls = {
276
+                    "smashlyon": [
277
+                        "https://resources.smashlyon.com/pplus/Olimar.zip",
278
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
279
+                        ],
280
+                    },
281
+                ),
282
+        Character(
283
+                smashggid = 1585,
284
+                name = "peach",
285
+                codenames = [ "Peach", ],
286
+                res_urls = {
287
+                    "smashlyon": [
288
+                        "https://resources.smashlyon.com/pplus/Peach.zip",
289
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
290
+                        ],
291
+                    },
292
+                ),
293
+        Character(
294
+                smashggid = 1603,
295
+                name = "pikachu",
296
+                codenames = [ "Pikachu", ],
297
+                res_urls = {
298
+                    "smashlyon": [
299
+                        "https://resources.smashlyon.com/pplus/Pikachu.zip",
300
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
301
+                        ],
302
+                    },
303
+                ),
304
+        Character(
305
+                smashggid = 1618,
306
+                name = "pit",
307
+                codenames = [ "pit", ],
308
+                res_urls = {
309
+                    "smashlyon": [
310
+                        "https://resources.smashlyon.com/pplus/Pit.zip",
311
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
312
+                        ],
313
+                    },
314
+                ),
315
+        Character(
316
+                smashggid = 1621,
317
+                name = "rob",
318
+                codenames = [ "Rob", ],
319
+                res_urls = {
320
+                    "smashlyon": [
321
+                        "https://resources.smashlyon.com/pplus/Rob.zip",
322
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
323
+                        ],
324
+                    },
325
+                ),
326
+        Character(
327
+                smashggid = 1615,
328
+                name = "roy",
329
+                codenames = [ "Roy", ],
330
+                res_urls = {
331
+                    "smashlyon": [
332
+                        "https://resources.smashlyon.com/pplus/Roy.zip",
333
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
334
+                        ],
335
+                    },
336
+                ),
337
+        Character(
338
+                smashggid = 1595,
339
+                name = "samus",
340
+                codenames = [ "samus", ],
341
+                res_urls = {
342
+                    "smashlyon": [
343
+                        "https://resources.smashlyon.com/pplus/Samus.zip",
344
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
345
+                        ],
346
+                    },
347
+                ),
348
+        Character(
349
+                smashggid = 1592,
350
+                name = "sheik",
351
+                codenames = [ "sheik", ],
352
+                res_urls = {
353
+                    "smashlyon": [
354
+                        "https://resources.smashlyon.com/pplus/Sheik.zip",
355
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
356
+                        ],
357
+                    },
358
+                ),
359
+        Character(
360
+                smashggid = 1622,
361
+                name = "snake",
362
+                codenames = [ "Snake", ],
363
+                res_urls = {
364
+                    "smashlyon": [
365
+                        "https://resources.smashlyon.com/pplus/Snake.zip",
366
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
367
+                        ],
368
+                    },
369
+                ),
370
+        Character(
371
+                smashggid = 1623,
372
+                name = "sonic",
373
+                codenames = [ "Sonic", ],
374
+                res_urls = {
375
+                    "smashlyon": [
376
+                        "https://resources.smashlyon.com/pplus/Sonic.zip",
377
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
378
+                        ],
379
+                    },
380
+                ),
381
+        Character(
382
+                smashggid = 1606,
383
+                name = "squirtle",
384
+                codenames = [ "squirtle", ],
385
+                res_urls = {
386
+                    "smashlyon": [
387
+                        "https://resources.smashlyon.com/pplus/Squirtle.zip",
388
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
389
+                        ],
390
+                    },
391
+                ),
392
+        Character(
393
+                smashggid = 1594,
394
+                name = "toon link",
395
+                codenames = [ "Toon Link", ],
396
+                res_urls = {
397
+                    "smashlyon": [
398
+                        "https://resources.smashlyon.com/pplus/Toon Link.zip",
399
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
400
+                        ],
401
+                    },
402
+                ),
403
+        Character(
404
+                smashggid = 1619,
405
+                name = "wario",
406
+                codenames = [ "Wario", ],
407
+                res_urls = {
408
+                    "smashlyon": [
409
+                        "https://resources.smashlyon.com/pplus/Wario.zip",
410
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
411
+                        ],
412
+                    },
413
+                ),
414
+        Character(
415
+                smashggid = 1601602,
416
+                name = "wolf",
417
+                codenames = [ "Wolf", ],
418
+                res_urls = {
419
+                    "smashlyon": [
420
+                        "https://resources.smashlyon.com/pplus/Wolf.zip",
421
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
422
+                        ],
423
+                    },
424
+                ),
425
+        Character(
426
+                smashggid = 1587,
427
+                name = "yoshi",
428
+                codenames = [ "Yoshi", ],
429
+                res_urls = {
430
+                    "smashlyon": [
431
+                        "https://resources.smashlyon.com/pplus/Yoshi.zip",
432
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
433
+                        ],
434
+                    },
435
+                ),
436
+        Character(
437
+                smashggid = 1591,
438
+                name = "zelda",
439
+                codenames = [ "Zelda", ],
440
+                res_urls = {
441
+                    "smashlyon": [
442
+                        "https://resources.smashlyon.com/pplus/Zelda.zip",
443
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
444
+                        ],
445
+                    },
446
+                ),
447
+        Character(
448
+                smashggid = 1596,
449
+                name = "zero suit samus",
450
+                codenames = [ "zss", ],
451
+                res_urls = {
452
+                    "smashlyon": [
453
+                        "https://resources.smashlyon.com/pplus/Zero Suit Samus.zip",
454
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
455
+                        ],
456
+                    },
457
+                ),
458
+        Character(
459
+                smashggid = 1617,
460
+                name = "mr game and watch",
461
+                codenames = [ "Gw", ],
462
+                res_urls = {
463
+                    "smashlyon": [
464
+                        "https://resources.smashlyon.com/pplus/Mr Game & Watch.zip",
465
+                        "https://resources.smashlyon.com/pplus/Stocks icons.zip",
466
+                        ],
467
+                    },
468
+                ),
469
+        Character(
470
+                smashggid = 1627,
471
+                name = "knuckles",
472
+                codenames = [ "knuckles", ],
473
+                res_urls = {
474
+                    "smashlyon": [
475
+                        ],
476
+                    },
477
+                ),
478
+        ]
479
+

File diff suppressed because it is too large
+ 1018 - 0
lokrez/games/ssbu.py


+ 2 - 1
lokrez/queries/getCharsByTournamentIdAndEntrantIds.gql

@@ -5,10 +5,11 @@ query getCharsByTournamentIdAndEntrantIds($tournamentId:ID, $entrantIds:[ID])
5 5
         events
6 6
         {
7 7
             name
8
+            slug
8 9
             numEntrants
9 10
             sets
10 11
             (
11
-                perPage:100
12
+                perPage:50
12 13
                 page:1
13 14
                 filters:
14 15
                 {

+ 1 - 0
lokrez/queries/getTournamentTopById.gql

@@ -14,6 +14,7 @@ query getTournamentTopBySlug($id:ID,$top:Int)
14 14
         events
15 15
         {
16 16
             name
17
+            slug
17 18
             numEntrants
18 19
             videogame
19 20
             {

+ 1 - 0
lokrez/queries/getTournamentTopBySlug.gql

@@ -14,6 +14,7 @@ query getTournamentTopBySlug($slug:String,$top:Int)
14 14
         events
15 15
         {
16 16
             name
17
+            slug
17 18
             numEntrants
18 19
             videogame
19 20
             {

+ 128 - 54
lokrez/resources.py

@@ -1,12 +1,12 @@
1 1
 import io
2
+import os
2 3
 import pathlib
3 4
 import sys
5
+import urllib
4 6
 import zipfile
5 7
 
6 8
 import requests
7 9
 
8
-from .characters_ssbu import EVERYONE
9
-
10 10
 # -----------------------------------------------------------------------------
11 11
 def download_file(url, with_progressbar = True, proxy = None):
12 12
 
@@ -45,86 +45,160 @@ def download_file(url, with_progressbar = True, proxy = None):
45 45
     return f
46 46
 
47 47
 # -----------------------------------------------------------------------------
48
-def download_res_ssbu(dstdir, proxy = None, log=None):
49
-    """Downloads SSBU resources from spriters and rename them according to
50
-    lokrez expectations"""
48
+def download_res(
49
+        dstdir,
50
+        game = None,
51
+        source = None,
52
+        store_raw = False,
53
+        proxy = None,
54
+        log = None,
55
+        ):
56
+    """TODO: Docstring for download_res_pplus.
57
+    :returns: TODO
58
+
59
+    """
60
+    if not game:
61
+        return
62
+
63
+    # Select default source if needed
64
+    if not source: