Add premices of challonge implementation

Not sure if I will go through with this. Challonge does not allow for
characters infos as far as I can tell.
master
Lertsenem 2020-12-03 09:36:17 +01:00
parent ee98d50417
commit a0414569ad
2 changed files with 63 additions and 0 deletions

View File

@ -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)

53
lokrez/challonge.py Normal file
View File

@ -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