Skip to content

Commit

Permalink
add new api file "leaguelevels"
Browse files Browse the repository at this point in the history
  • Loading branch information
joschobart committed Aug 30, 2024
1 parent 6746fbe commit 3c77a5c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 76 deletions.
32 changes: 20 additions & 12 deletions fun_with_flags/api.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
"""hattrick-libs api-client functions"""

from flask import session
from ht_libs import (
do_challenge,
do_hattrick_request,
get_flags,
get_matchdetails,
get_matches,
get_series,
get_teamdetails,
get_trainer_avatar,
get_worlddetails,
request_token_status,
)
from ht_libs import (do_challenge, do_hattrick_request, get_flags,
get_leaguelevels, get_matchdetails, get_matches,
get_series, get_teamdetails, get_trainer_avatar,
get_worlddetails, request_token_status)

from . import helperf

Expand Down Expand Up @@ -63,6 +55,11 @@
"teamId": "", # id of team to manage
"isWeekendFriendly": "0",
},
"leaguelevels": {
"file": "leaguelevels",
"version": "1.0",
"LeagueID": "",
},
"get_trainer_avatar": {
"file": "staffavatars",
"version": "1.1",
Expand Down Expand Up @@ -199,6 +196,17 @@ def ht_get_flags(teamdetails_xml):
return flags_dict


def ht_get_leaguelevels(leaguelevels_xml):
"""
:param leaguelevels_xml:
"""
leaguelevels_dict = get_leaguelevels.get_leaguelevels(leaguelevels_xml)

return leaguelevels_dict


def ht_get_matchdetails(matchdetails_xml):
"""
Expand Down
69 changes: 12 additions & 57 deletions fun_with_flags/helperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,72 +266,27 @@ def get_my_teams():

def get_series_list(flagid, search_level=2, fernet_token=""):
"""
:param flagid:
:param search_level: (Default value = 2)
:param fernet_token: (Default value = "")
(1, "i", 1),
(2, "ii", 4), # <------ default (search_level=2)
(3, "iii", 16),
(4, "iv", 64),
(5, "v", 256), # <------ 341 series, max. 2728 teams (deep-search)
(6, "vi", 1024),
"""

def get_series_id(search_string, flagid):
"""
:param search_string:
:param flagid:
"""
api_response = api.ht_get_data(
"search_series",
searchString=search_string,
searchLeagueID=flagid,
fernet_token=fernet_token,
)

probe_list.append(api.ht_get_series(api_response)["series_id"])
_xml = api.ht_get_data("leaguelevels", LeagueID=flagid, fernet_token=fernet_token)
league_levels = api.ht_get_leaguelevels(_xml)

return probe_list

probe_list = []
series_list = []

# fmt: off
league_table = [
(2, "ii", 4),
(3, "iii", 16),
(4, "iv", 64), # <------ default (search_level=2)
(5, "v", 256), # <------ 340 series, max. 2720 teams (deep-search)
(6, "vi", 1024),
]
# fmt: on

_xml = api.ht_get_data("worlddetails", leagueID=flagid, fernet_token=fernet_token)
league_depth = api.ht_get_worlddetails(_xml)

# Here the depth of
# the loop is adjustable
for l_tuple in league_table[0:search_level]:
if l_tuple[0] > int(league_depth["league_depth"]):
for league_level in range(0, int(search_level)):
if league_level >= int(league_levels["league_depth"]):
break

l_numbers = 1, l_tuple[2]

for l_number in l_numbers:
get_series_id(f"{l_tuple[1]}.{l_number}", flagid)

lid_difference = int(probe_list[1]) - int(probe_list[0])
l_difference = l_tuple[2] - 1

if lid_difference != l_difference:
print(
"WARNING: anomaly in leagueID numbering found. do pricy loops as fallback."
)
# not integrated yet

else:
for i in range(int(probe_list[0]), int(probe_list[1]) + 1):
series_list.append(i)

probe_list.clear()
league_level_unit_ids = league_levels["league_levels"][league_level]["lluid_list"]
series_list += league_level_unit_ids

# shuffle series list to
# load-balance requests
Expand Down
8 changes: 4 additions & 4 deletions instance/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"settings": {
"meta": {
"schema_version": 6.3,
"schema_version": 6.4,
"date_initialized": "",
"date_updated": "",
},
Expand All @@ -65,7 +65,7 @@
"League Search Depth",
"Default: 2; The higher the number, the deeper the search, the longer it \
takes to find potential opponents but also the more potential opponents there are.",
["1", "2", "3", "4", "5"],
["1", "2", "3", "4", "5", "6"],
),
"match_rules": (
"Match Rules",
Expand All @@ -92,7 +92,7 @@
"Durchsuchungstiefe",
"Standard: 2; Je höher die Zahl umso tiefer die Suche im Ligabaum. Dadurch \
verlängert sich die Suchzeit, aber es vergrössert sich auch die Chance, einen potentiellen Gegner zu finden.",
["1", "2", "3", "4", "5"],
["1", "2", "3", "4", "5", "6"],
),
"match_rules": (
"Matchregeln",
Expand All @@ -119,7 +119,7 @@
"Profondeur de la recherche dans la ligue ",
"Par défaut : 2 ; Plus le nombre est élevé, plus la recherche est approfondie, plus il \
faut de temps pour trouver des adversaires potentiels, mais aussi plus il y a d'adversaires potentiels.",
["1", "2", "3", "4", "5"],
["1", "2", "3", "4", "5", "6"],
),
"match_rules": (
"Règles de match ",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = [
{ name = "joe", email = "github@schicker.guru" }
]
dependencies = [
"hattrick-libs==0.17.1",
"hattrick-libs==0.18.0",
"flask==3.0.3",
"cryptography>=41.0.7",
"CouchDB>=1.2",
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ flask-babel==4.0.0
# via hattrick-fwf
gunicorn==21.2.0
# via hattrick-fwf
hattrick-libs==0.17.1
hattrick-libs==0.18.0
# via hattrick-fwf
idna==3.6
# via requests
Expand Down
2 changes: 1 addition & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ flask-babel==4.0.0
# via hattrick-fwf
gunicorn==21.2.0
# via hattrick-fwf
hattrick-libs==0.17.1
hattrick-libs==0.18.0
# via hattrick-fwf
idna==3.6
# via requests
Expand Down

0 comments on commit 3c77a5c

Please sign in to comment.