-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from flbraun/other-leagues-data-support
Support for Challenge HC, Standard and HC (requires restart)
- Loading branch information
Showing
13 changed files
with
287 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
from collections.abc import Generator | ||
|
||
from .leagues import League | ||
from .ninja import get_ninja_index, make_ninja_url | ||
from .trade import make_trade_url | ||
from .types import NinjaCategory | ||
from .utils import Entry, make_wiki_url | ||
|
||
|
||
def get_beasts() -> Generator[Entry, None, None]: | ||
index = get_ninja_index() | ||
def get_beasts(league: League) -> Generator[Entry, None, None]: | ||
index = get_ninja_index(league) | ||
|
||
for beast in index.raw[NinjaCategory.BEASTS]: | ||
yield Entry( | ||
display_text=beast, | ||
wiki_url=make_wiki_url(beast), | ||
ninja_url=make_ninja_url(beast, None, NinjaCategory.BEASTS), | ||
trade_url=make_trade_url(beast), | ||
ninja_url=make_ninja_url(league, beast, None, NinjaCategory.BEASTS), | ||
trade_url=make_trade_url(league, beast), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import dataclasses | ||
import functools | ||
import http | ||
|
||
from tabulate import tabulate | ||
|
||
from .types import LeagueType | ||
from .utils import LoggedRequestsSession, slugify | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class League: | ||
type_: LeagueType | ||
title: str # e.g. "Ancestor" | ||
slug: str # e.g. "ancestor" | ||
is_hardcore: bool | ||
|
||
|
||
@functools.cache | ||
def get_leagues() -> dict[LeagueType, League]: | ||
session = LoggedRequestsSession() | ||
|
||
res = session.get('https://poe.ninja/api/data/getindexstate') | ||
assert res.status_code == http.HTTPStatus.OK | ||
|
||
res_parsed = res.json() | ||
|
||
leagues = { | ||
LeagueType.STANDARD: League( | ||
type_=LeagueType.STANDARD, | ||
title='Standard', | ||
slug='standard', | ||
is_hardcore=False, | ||
), | ||
LeagueType.HARDCORE: League( | ||
type_=LeagueType.HARDCORE, | ||
title='Hardcore', | ||
slug='hardcore', | ||
is_hardcore=True, | ||
), | ||
} | ||
|
||
# challenge league usually is the first | ||
challenge_league_name = res_parsed['economyLeagues'][0]['name'] | ||
assert challenge_league_name != 'Standard', challenge_league_name | ||
assert 'Hardcore' not in challenge_league_name, challenge_league_name | ||
assert 'Ruthless' not in challenge_league_name, challenge_league_name | ||
assert 'HC' not in challenge_league_name, challenge_league_name | ||
|
||
leagues[LeagueType.CHALLENGE] = League( | ||
type_=LeagueType.CHALLENGE, | ||
title=challenge_league_name, | ||
slug=slugify(challenge_league_name), | ||
is_hardcore=False, | ||
) | ||
leagues[LeagueType.CHALLENGE_HARDCORE] = League( | ||
type_=LeagueType.CHALLENGE_HARDCORE, | ||
title=f'Hardcore {challenge_league_name}', | ||
slug=f'{leagues[LeagueType.CHALLENGE].slug}hc', | ||
is_hardcore=True, | ||
) | ||
|
||
print( | ||
tabulate( | ||
[[league_type, league.title, league.slug, league.is_hardcore] for league_type, league in leagues.items()], | ||
headers=('league type', 'human', 'slug', 'is hardcore'), | ||
tablefmt='outline', | ||
), | ||
) | ||
|
||
return leagues |
Oops, something went wrong.