-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tomato_info_class.py
70 lines (48 loc) · 3.36 KB
/
Tomato_info_class.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
import requests
# HELPER FUNCTIONS
def dictComp(list): return {int(tank["id"]): tank for tank in list["recent1000"]["tankStats"]}
class TomatoGGInfo:
def __init__(self, server, user_name):
self.username = user_name
self.playerServer = server.lower()
# find account ID using WG's API
if self.playerServer == "na":
account_id = ((requests.get("https://api.worldoftanks.com/wot/account/list/?application_id=bd644ca5adf8dc631b1598528a4b7fc1&search=" + self.username)).json())\
["data"][0]["account_id"] # DICT value keys for userID
else:
account_id = requests.get("https://api.worldoftanks." + self.playerServer + "/wot/account/list/?application_id=bd644ca5adf8dc631b1598528a4b7fc1&search=" + self.username)
self.accountID = (account_id.json())["data"][0]["account_id"]
# tomato.gg
if self.playerServer == "na":
self.tomatoInfo = (requests.get(f"https://tomatobackend.herokuapp.com/api/player/com/{str(self.accountID)}")).json() #
else:
tomato_json = requests.get(f"https://tomatobackend.herokuapp.com/api/player/{self.playerServer}/{str(self.accountID)}")
print(f"Status code is {tomato_json.status_code}")
# if status code is not 200
counter = 0
while tomato_json.status_code != 200:
counter += 1
tomato_json = requests.get(f"https://tomatobackend.herokuapp.com/api/player/{self.playerServer}/{str(self.accountID)}")
print(f"{counter} times pinging API, status code is {tomato_json.status_code}\n")
self.tomatoInfo = tomato_json.json()
print("QB recent stats initialized")
self.recentStats = self.tomatoInfo["recents"]
# Recent stats by battles *includes battles, overall wins, wn8, and has specific tank stats
self.recent1000 = self.recentStats["recent1000"]
self.recent1000Tanks = dictComp(self.recentStats) # tank_id from tomato backed is in str format
self.recent100 = self.recentStats["recent100"]
# Recent stats by days
self.recent24hr = self.recentStats["recent24hr"]
self.recent3days = self.recentStats["recent3days"]
self.recent7days = self.recentStats["recent7days"]
self.recent30days = self.recentStats["recent30days"]
self.recent60days = self.recentStats["recent60days"]
def WR(self, wins, battles):
return str(round(((wins/battles) * 100), 2))
# doesnt work
def discordRecentsString(self):
return (f"> **24 hr Recents:** {str(self.recent24hr['overallWN8'])} wn8 | {self.WR(self.recent24hr['wins'], self.recent24hr['battles'])} % WR\n"
f"> **3 Day Recents:** {str(self.recent3days['overallWN8'])} wn8 | {self.WR(self.recent3days['wins'], self.recent3days['battles'])} % WR\n"
f"> **7 Day Recents:** {str(self.recent7days['overallWN8'])} wn8 | {self.WR(self.recent7days['wins'], self.recent7days['battles'])} % WR\n"
f"> **30 Day Recents:** {str(self.recent30days['overallWN8'])} wn8 | {self.WR(self.recent30days['wins'], self.recent30days['battles'])} % WR\n"
f"> **60 Day Recents:** {str(self.recent60days['overallWN8'])} wn8 | {self.WR(self.recent60days['wins'], self.recent60days['battles'])} % WR\n")