From a454625207252b50d7dc45c059f75b6605e276e3 Mon Sep 17 00:00:00 2001 From: Lertsenem Date: Thu, 17 Sep 2020 15:06:23 +0200 Subject: [PATCH] Add support for json url for playerskins DB --- lokrez/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lokrez/__init__.py b/lokrez/__init__.py index 80238f7..c599b85 100644 --- a/lokrez/__init__.py +++ b/lokrez/__init__.py @@ -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