Add support for json url for playerskins DB

master
Lertsenem 2020-09-17 15:06:23 +02:00
parent b9e7ed45b7
commit a454625207
1 changed files with 9 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import html
import json
import logging
import pathlib
import requests
import sys
import appdirs
@ -87,10 +88,10 @@ def main():
)
top8_parser.add_argument(
"--playerskinsdb", "-PD",
type = pathlib.Path,
type = (lambda s: s if s.startswith("http") else pathlib.Path(s)),
default = ROOTDIR / "data" / "playerskinsdb.json",
help = "A JSON file matching player tags, characters and " \
"preferred skins",
help = "A JSON file path or urk matching player tags, characters,"\
" sponsors, and preferred skins",
)
top8_parser.add_argument(
"--cachedir", "-CD",
@ -209,8 +210,11 @@ def main():
# Initialize PLAYERSKINS db
log.debug("loading playerskins db from '{}'" \
.format(args.playerskinsdb))
with args.playerskinsdb.open("r", encoding="utf8") as f:
smashgg.PLAYERSKINS = json.load(f)
try:
smashgg.PLAYERSKINS = requests.get(args.playerskinsdb).json()
except:
with args.playerskinsdb.open("r", encoding="utf8") as f:
smashgg.PLAYERSKINS = json.load(f)
#
tournament = None