Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mxrch
GitHub Repository: mxrch/GHunt
Path: blob/master/ghunt/helpers/playgames.py
253 views
1
from ghunt.objects.base import GHuntCreds
2
from ghunt.apis.playgames import PlayGames
3
from ghunt.apis.playgateway import PlayGatewayPaGrpc
4
from ghunt.parsers.playgames import Player, PlayerProfile
5
from ghunt.parsers.playgateway import PlayerSearchResult
6
from ghunt.objects.utils import TMPrinter
7
8
import httpx
9
from alive_progress import alive_bar
10
11
from typing import *
12
13
14
async def get_player(ghunt_creds: GHuntCreds, as_client: httpx.AsyncClient, player_id: str):
15
playgames = PlayGames(ghunt_creds)
16
17
tmprinter = TMPrinter()
18
tmprinter.out("[~] Getting player profile...")
19
is_found, player_profile = await playgames.get_profile(as_client, player_id)
20
tmprinter.clear()
21
if not is_found or not player_profile.profile_settings.profile_visible:
22
return is_found, Player()
23
24
playgateway_pa = PlayGatewayPaGrpc(ghunt_creds)
25
player_stats = await playgateway_pa.get_player_stats(as_client, player_id)
26
27
with alive_bar(player_stats.played_games_count, title="🚎 Fetching played games...", receipt=False) as bar:
28
_, next_page_token, played_games = await playgames.get_played_games(as_client, player_id)
29
bar(len(played_games.games))
30
while next_page_token:
31
_, next_page_token, new_played_games = await playgames.get_played_games(as_client, player_id, next_page_token)
32
played_games.games += new_played_games.games
33
bar(len(new_played_games.games))
34
35
with alive_bar(player_stats.achievements_count, title="🚎 Fetching achievements...", receipt=False) as bar:
36
_, next_page_token, achievements = await playgames.get_achievements(as_client, player_id)
37
bar(len(achievements.achievements))
38
while next_page_token:
39
_, next_page_token, new_achievements = await playgames.get_achievements(as_client, player_id, next_page_token)
40
achievements.achievements += new_achievements.achievements
41
bar(len(new_achievements.achievements))
42
43
player = Player(player_profile, played_games.games, achievements.achievements)
44
return is_found, player
45
46
async def search_player(ghunt_creds: GHuntCreds, as_client: httpx.AsyncClient, query: str) -> List[PlayerSearchResult]:
47
playgateway_pa = PlayGatewayPaGrpc(ghunt_creds)
48
player_search_results = await playgateway_pa.search_player(as_client, query)
49
return player_search_results.results
50
51
def output(player: Player):
52
if not player.profile.profile_settings.profile_visible:
53
print("\n[-] Profile is private.")
54
return
55
56
print("\n[+] Profile is public !")
57
print(f"\n[+] Played to {len(player.played_games)} games")
58
print(f"[+] Got {len(player.achievements)} achievements")
59
60
if player.played_games:
61
print(f"\n[+] Last played game : {player.profile.last_played_app.app_name} ({player.profile.last_played_app.timestamp_millis} UTC)")
62
63
if player.achievements:
64
app_ids_count = {}
65
for achievement in player.achievements:
66
if (app_id := achievement.app_id) not in app_ids_count:
67
app_ids_count[app_id] = 0
68
app_ids_count[app_id] += 1
69
app_ids_count = dict(sorted(app_ids_count.items(), key=lambda item: item[1], reverse=True))
70
achiv_nb = list(app_ids_count.values())[0]
71
target_game = None
72
for game in player.played_games:
73
if game.game_data.id == list(app_ids_count.keys())[0]:
74
target_game = game
75
break
76
77
print(f"[+] Game with the most achievements : {target_game.game_data.name} ({achiv_nb})")
78