-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
188 lines (149 loc) · 10.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
__author__ = "Charles Petchsy"
__license__ = "MIT"
__maintainer__ = "Charles Petchsy"
__status__ = "Alpha"
import requests
import json
import ast
import time
import discord
from discord.ext import commands
from html.parser import HTMLParser
class Lifetime(HTMLParser):
""" Parse requirements:
Each entry will include the rank percentile of the player.
PvP Kills
NPC Kills
Skill Kills
Headshots
Items Looted
E-Credit Balance
Commendations
Curr Comm. Score
Sharpshooter Kills
Survivalist Kills
Demolitionist Kills
-> PvE Stats
-> PvP Stats
"""
def handle_data(self, data):
output = """"""
separator = "\n---------------------------------------------------------\n"
if 'window.__INITIAL_STATE__' in data:
player_data = json.loads(
ast.literal_eval(
repr(data.split(';')[0].split('=')[1])
)
)
root_key = next(iter(player_data['stats']['standardPlayers']))
# print(root_key)
# get player data
player_name = root_key.split('|')[2]
output += "Username: " + player_name.upper() + "\n"
# get gear score
output += "====================\n"
gear_score = player_data['stats']['standardPlayers'][root_key]['stats']['latestGearScore']['displayValue']
gear_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['latestGearScore']['displayPercentile'])
output += "Gear Score: " + gear_score + " " + " [ " + gear_rank + " ]"
output += "\n====================\n\n"
output += "Lifetime Stats"
output += separator
# get pvp kills
pvp_kills = player_data['stats']['standardPlayers'][root_key]['stats']['killsPvP']['displayValue']
pvp_rank = player_data['stats']['standardPlayers'][root_key]['stats']['killsPvP']['displayPercentile']
output += "PvP Kills: " + pvp_kills + " " + " [ " + pvp_rank + " ]" + "\n"
# get npc kills
npc_kills = player_data['stats']['standardPlayers'][root_key]['stats']['killsNpc']['displayValue']
npc_rank = player_data['stats']['standardPlayers'][root_key]['stats']['killsNpc']['displayPercentile']
output += "NPC Kills: " + npc_kills + " " + " [ " + npc_rank + " ]" + "\n"
# get skill kills
skill_kills = player_data['stats']['standardPlayers'][root_key]['stats']['killsSkill']['displayValue']
skill_rank = player_data['stats']['standardPlayers'][root_key]['stats']['killsSkill']['displayPercentile']
output += "Skill Kills: " + skill_kills + " " + " [ " + skill_rank + " ]" + "\n"
# get headshot kills
headshot_kills = player_data['stats']['standardPlayers'][root_key]['stats']['headshots']['displayValue']
headshot_rank = player_data['stats']['standardPlayers'][root_key]['stats']['headshots']['displayPercentile']
output += "Headshots: " + headshot_kills + " " + " [ " + headshot_rank + " ]" + "\n"
# get items looted
items_looted = player_data['stats']['standardPlayers'][root_key]['stats']['itemsLooted']['displayValue']
items_rank = player_data['stats']['standardPlayers'][root_key]['stats']['itemsLooted']['displayPercentile']
output += "Items Looted: " + items_looted + " " + " [ " + items_rank + " ]" + "\n"
# get credit balance
credit_balance = str(player_data['stats']['standardPlayers'][root_key]['stats']['eCreditBalance']['displayValue'])
balance_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['eCreditBalance']['displayPercentile'])
output += "E-Credit Balance: " + credit_balance + " " + " [ " + balance_rank + " ]" + "\n"
# get commendations
comm_count = str(player_data['stats']['standardPlayers'][root_key]['stats']['commendationCount']['displayValue'])
comm_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['commendationCount']['displayPercentile'])
output += "Commendations: " + comm_count + " " + " [ " + comm_rank + " ]" + "\n"
# get sharpshooter kills
sharpshooter_kills = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsSpecializationSharpshooter']['displayValue'])
sharpshooter_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsSpecializationSharpshooter']['displayPercentile'])
output += "Sharpshooter (Spec) Kills: " + sharpshooter_kills + " " + " [ " + sharpshooter_rank + " ]" + "\n"
# get sharpshooter kills
survivalist_kills = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsSpecializationSurvivalist']['displayValue'])
survivalist_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsSpecializationSurvivalist']['displayPercentile'])
output += "Survivalist (Spec) Kills: " + survivalist_kills + " " + " [ " + survivalist_rank + " ]" + "\n"
# get sharpshooter kills
demolitionist_kills = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsSpecializationDemolitionist']['displayValue'])
demolitionist_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsSpecializationDemolitionist']['displayPercentile'])
output += "Demolitionist (Spec) Kills: " + demolitionist_kills + " " + " [ " + demolitionist_rank + " ]" + "\n\n"
# get PVE stats
output += "PvE Stats"
output += separator
pve_exp = str(player_data['stats']['standardPlayers'][root_key]['stats']['xPPve']['displayValue'])
pve_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['xPPve']['displayPercentile'])
output += "PvE XP: " + pve_exp + " " + " [ " + pve_rank + " ]" + "\n"
time_played = str(player_data['stats']['standardPlayers'][root_key]['stats']['timePlayed']['displayValue'])
time_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['timePlayed']['displayPercentile'])
output += "Time Played: " + time_played + " " + " [ " + time_rank + " ]" + "\n"
named_kills = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsRoleNamed']['displayValue'])
named_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsRoleNamed']['displayPercentile'])
output += "Named Kills: " + named_kills + " " + " [ " + named_rank + " ]" + "\n"
hyena_kills = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsFactionBlackbloc']['displayValue'])
hyena_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsFactionBlackbloc']['displayPercentile'])
output += "Hyena Kills: " + hyena_kills + " " + " [ " + hyena_rank + " ]" + "\n"
outcast_kills = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsFactionCultists']['displayValue'])
outcast_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsFactionCultists']['displayPercentile'])
output += "OutCasts Kills: " + outcast_kills + " " + " [ " + outcast_rank + " ]" + "\n"
truesons_kills = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsFactionMilitia']['displayValue'])
truesons_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsFactionMilitia']['displayPercentile'])
output += "Truesons Kills: " + truesons_kills + " " + " [ " + truesons_rank + " ]" + "\n"
blacktusk_kills = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsFactionEndgame']['displayValue'])
blacktusk_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['killsFactionEndgame']['displayPercentile'])
output += "BlackTusk Kills: " + blacktusk_kills + " " + " [ " + blacktusk_rank + " ]" + "\n\n"
# get PVP stats
output += "PvP Stats"
output += separator
pvp_exp = str(player_data['stats']['standardPlayers'][root_key]['stats']['xPDZ']['displayValue'])
pvp_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['xPDZ']['displayPercentile'])
output += "PvP XP: " + pvp_exp + " " + " [ " + pvp_rank + " ]" + "\n"
dz_time = str(player_data['stats']['standardPlayers'][root_key]['stats']['timePlayedDarkZone']['displayValue'])
dz_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['timePlayedDarkZone']['displayPercentile'])
output += "Time Played: " + dz_time + " " + " [ " + dz_rank + " ]" + "\n"
rogue_time = str(player_data['stats']['standardPlayers'][root_key]['stats']['timePlayedRogue']['displayValue'])
rogue_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['timePlayedRogue']['displayPercentile'])
output += "Rogue Time: " + rogue_time + " " + " [ " + rogue_rank + " ]" + "\n"
players_killed = str(player_data['stats']['standardPlayers'][root_key]['stats']['roguesKilled']['displayValue'])
playerKill_rank = str(player_data['stats']['standardPlayers'][root_key]['stats']['roguesKilled']['displayPercentile'])
output += "Rogues Killed: " + players_killed + " " + " [ " + playerKill_rank + " ]" + "\n"
self.data = output
bot = commands.Bot(command_prefix='!')
@bot.command()
async def shd(ctx, arg):
start_time = round(time.time() * 1000)
if arg.lower() == "help":
await ctx.channel.send("Get player stats: !shd <player_name>\nBot ping test: !shd ping")
elif arg.lower() == "ping":
end_time = round(time.time() * 1000)
await ctx.channel.send("pong (%s ms)" % str(end_time - start_time))
else:
try:
r = requests.get('https://division.tracker.gg/division-2/profile/uplay/%s/overview' % arg)
parser = Lifetime()
parser.feed(str(r.content))
await ctx.channel.send(parser.data)
except (TypeError, KeyError):
await ctx.channel.send("Player does not exist!")
if __name__ == '__main__':
bot.run('') # Include token here.