Some little features/improvements
Closed this issue · 3 comments
Xample33 commented
I have added some very simple features that add new variables and makes the traceback cleaner.
- In
player.py
:load_playtime
a new variable called total_time_played_hours (self explanatory):
async def load_playtime(self) -> None:
data = await self._auth.get(self._url_builder.playtime())
stats = data.get("profiles", [])[0].get("stats", {})
self.level = int(stats.get("PClearanceLevel", {}).get("value", 0))
self.pvp_time_played = int(stats.get("PPvPTimePlayed", {}).get("value", 0))
self.pve_time_played = int(stats.get("PPvETimePlayed", {}).get("value", 0))
self.total_time_played = int(stats.get("PTotalTimePlayed", {}).get("value", 0))
self.total_time_played_hours = self.total_time_played // 3600 if self.total_time_played else 0
- In
auth.py
:_find_players
in case of no results, close the connection before raisingInvalidRequest
to avoidUnclosed connector
exception in the traceback: (this can be applied to every raise in_find_players
and maybe other methods)
async def _find_players(self, name: str, platform: str, uid: str) -> list[Player]:
. . .
. . .
. . .
if "profiles" in data:
results = [Player(self, x) for x in data["profiles"] if x.get("platformType", "") == platform]
if len(results) == 0:
await self.close()
raise InvalidRequest("No results")
return results
else:
raise InvalidRequest(f"Missing key profiles in returned JSON object {str(data)}")
Maybe these are worth or useful, lmk what you think
CNDRD commented
Oh yeah for sure these are all good ideas.
The await self.close()
could theoretically be added before every raise
to avoid the Unclosed connector
exception
I will add all of this once I get home later today (or you can submit a PR if you want 😃)
Xample33 commented
Thanks!
I made some little fixes and submitted the PR.
CNDRD commented
Coolio 😄
The new version got published to PyPI a few moments ago and is also available as a release here on GitHub