Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some little features/improvements #18

Closed
Xample33 opened this issue Sep 19, 2023 · 3 comments
Closed

Some little features/improvements #18

Xample33 opened this issue Sep 19, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request will do Will fix/update/edit

Comments

@Xample33
Copy link
Contributor

I have added some very simple features that add new variables and makes the traceback cleaner.

  1. 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

  1. In auth.py: _find_players in case of no results, close the connection before raising InvalidRequest to avoid Unclosed 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 CNDRD self-assigned this Sep 19, 2023
@CNDRD CNDRD added enhancement New feature or request will do Will fix/update/edit labels Sep 19, 2023
@CNDRD
Copy link
Owner

CNDRD commented Sep 19, 2023

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
Copy link
Contributor Author

Thanks!
I made some little fixes and submitted the PR.

@CNDRD
Copy link
Owner

CNDRD commented Sep 19, 2023

Coolio 😄

The new version got published to PyPI a few moments ago and is also available as a release here on GitHub

@CNDRD CNDRD closed this as completed Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request will do Will fix/update/edit
Projects
None yet
Development

No branches or pull requests

2 participants