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