Skip to content
This repository was archived by the owner on Sep 7, 2024. It is now read-only.

Commit 10137bd

Browse files
authored
Merge pull request #8 from gunnarsnorri/master
Fix League Points being interpreted as unknown
2 parents 4ce49e5 + f4dc293 commit 10137bd

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

osrs_api/const.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ class AccountType(Enum):
1212

1313
@classmethod
1414
def normal_types(cls):
15-
return [cls.NORMAL, cls.IRONMAN, cls.HARDCORE_IRONMAN, cls.ULTIMATE_IRONMAN]
15+
return [cls.NORMAL,
16+
cls.IRONMAN,
17+
cls.HARDCORE_IRONMAN,
18+
cls.ULTIMATE_IRONMAN]
1619

1720

18-
# Thanks to http://mirekw.com/rs/RSDOnline/Guides/guide.aspx?file=Experience%20formula.html for the formula
21+
# Thanks to
22+
# http://mirekw.com/rs/RSDOnline/Guides/guide.aspx?file=Experience%20formula.html
23+
# for the formula
1924
def _build_xp_table():
2025
table = [0]
2126
xp = 0
@@ -31,8 +36,6 @@ def _build_xp_table():
3136
# index retrives the amount of xp required for level index + 1
3237
XP_TABLE = _build_xp_table()
3338

34-
UNUSED_OR_UNKNOWN = "UNUSED_OR_UNKNOWN" # Use this as a placeholder for unknown API response rows
35-
3639
SKILLS = [
3740
"attack",
3841
"defence",
@@ -60,7 +63,7 @@ def _build_xp_table():
6063
]
6164

6265
MINIGAMES = [
63-
UNUSED_OR_UNKNOWN,
66+
"League Points",
6467
"Bounty Hunter",
6568
"Bounty Hunter Rogue",
6669
"Clue Scrolls (all)",

osrs_api/hiscores.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, username, account_type=None):
1818
self._api_response = None
1919

2020
if self._type is None:
21-
self._find_account_type() # _type is set inside _find_account_type
21+
self._find_account_type() # _type is set inside _find_account_type
2222

2323
self.rank, self.total_level, self.total_xp = -1, -1, -1
2424

@@ -29,7 +29,8 @@ def __init__(self, username, account_type=None):
2929
self.update()
3030

3131
def update(self):
32-
# In the default case (account_type=None), we already have this information. We don't need to do it again
32+
# In the default case (account_type=None), we already have this
33+
# information. We don't need to do it again
3334
if self._api_response is None:
3435
self._api_response = self._get_api_data()
3536
self._set_data()
@@ -50,7 +51,7 @@ def _find_account_type(self):
5051
self._type = possible_type
5152
self._api_response = self._get_api_data()
5253
return
53-
except:
54+
except BaseException:
5455
pass
5556

5657
self._raise_bad_username()
@@ -87,7 +88,7 @@ def _set_data(self):
8788
# Get all the skills, minigames, or bosses
8889
def _get_api_chunk(cls, *, names, start_index):
8990
"""
90-
cls: Skill, Minigame, or Boss - Type of the chunk
91+
cls: Skill, Minigame, or Boss - Type of the chunk
9192
names: List[str] - a list of all the (Skill, Minigame, or Boss) names in the order the API returns them.
9293
(const.SKILLS, const.MINIGAMES, or const.BOSSES)
9394
start_index: The index into self._api_response where the chunk begins
@@ -96,11 +97,13 @@ def _get_api_chunk(cls, *, names, start_index):
9697
chunk = {}
9798

9899
for i, name in enumerate(names, start=start_index):
99-
if name == const.UNUSED_OR_UNKNOWN:
100+
if (self._type is not const.AccountType.SEASONAL and name ==
101+
"League Points"):
100102
continue
101103

102104
# The API only returns integers
103-
row_data = [int(col) for col in self._api_response[i].split(",")]
105+
row_data = [int(col)
106+
for col in self._api_response[i].split(",")]
104107

105108
chunk[name] = cls(name, *row_data)
106109

0 commit comments

Comments
 (0)