diff --git a/lokrez/__init__.py b/lokrez/__init__.py index afb163b..749ba2e 100644 --- a/lokrez/__init__.py +++ b/lokrez/__init__.py @@ -345,6 +345,16 @@ def getTournamentTop( """Returns a tuple : the smashgg.Tournament object and a list of the top smashgg.Player in that tournament.""" + # TODO if url matches challonge + # + #data = challonge.get_participants( + # api_key = token, + # tournament = id_or_slug, + # ) + # + #top_array = []*top + #for p in data: + # top_array[p["participant"]["final_rank"]] = ... # ------------------------------------------------------------------------- # Select the right event (the one with the most entrants or the most sets) diff --git a/lokrez/challonge.py b/lokrez/challonge.py new file mode 100644 index 0000000..0632b44 --- /dev/null +++ b/lokrez/challonge.py @@ -0,0 +1,53 @@ +import json +import os, os.path +import pathlib + +import requests + +from . import characters_ssbu + +# ============================================================================= +API_HOST = "api.challonge.com" +API_ENDPOINT = "v1" +API_SCHEME = "https" +API_URL = "{scheme}://{host}/{endpoint}".format( + scheme = API_SCHEME, + host = API_HOST, + endpoint = API_ENDPOINT, + ) + +CHARACTERS = { c.smashggid : c.name for c in characters_ssbu.EVERYONE } + +PLAYERSKINS = {} + + +# ============================================================================= +def get_participants( api_key, tournament, proxy = None, log = None ): + + payload = { + "api_key": api_key, + } + headers = { + "Accept": "application/json", + "Content-Type": "application/json" + } + + rv = requests.get( + "{url}/{tournament}/participants.json".format( + url = API_URL, + tournament = tournament, + ) + json.dumps(payload).encode("utf-8"), + headers = headers, + proxies = { "http": proxy, "https": proxy}, + ) + + try: + rv_json = rv.json() + except Exception as e: + log.error("HTTP request failed") + log.error(e) + log.debug(e, exc_info=True) + log.debug(rv) + + return rv_json