forked from Stepheny755/ClanStatsBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.py
More file actions
195 lines (160 loc) · 5.91 KB
/
API.py
File metadata and controls
195 lines (160 loc) · 5.91 KB
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
189
190
191
192
193
194
195
import json,requests
import urllib.request
from time import sleep
from util import Util
#TODO:
#Pull API Data for players from WG API
class API():
ID = ''
claninfoep = 'https://api.worldofwarships.com/wows/clans/info/'
clanlistep = 'https://api.worldofwarships.com/wows/clans/list/'
accinfoep = 'https://api.worldofwarships.com/wows/account/info/'
acclistep = 'https://api.worldofwarships.com/wows/account/list/'
pediaep = 'https://api.worldofwarships.com/wows/encyclopedia/ships/'
shipstatep = 'https://api.worldofwarships.com/wows/ships/stats/'
wowsnumep = 'https://wows-numbers.com/personal/rating/expected/json/'
#Data for expected values used to calculate PR pulled
#from the official wows-numbers website: https://wows-numbers.com
def __init__(self):
self.ID=open('ID.txt',"r").read().strip()
# INIT
# PLAYER RELATED FUNCTIONS
def getPlayerID(self,name):
data={'application_id':self.ID,'search':name.strip()}
r = requests.post(self.acclistep,data)
try:
return json.loads(r.text)['data'][0]['account_id']
except:
return None
def getPlayerName(self,ID):
data={'application_id':self.ID,'account_id':ID}
r = requests.post(self.accinfoep,data)
try:
return json.loads(r.text)['data'][str(ID)]['nickname']
except:
return None
def getPlayerCard(self,ID):
data={'application_id':self.ID,'account_id':ID}
r = requests.post(self.accinfoep,data)
try:
return json.loads(r.text)['data'][str(ID)]
except:
return None
def getPlayerStats(self,ID):
sleep(0.1)
data=self.getPlayerCard(ID)
return data['statistics']
def getPlayerBattles(self,ID):
data = self.getPlayerStats(ID)
return int(data['pvp']['battles'])
def getPlayerWins(self,ID):
data=self.getPlayerStats(ID)
return int(data['pvp']['wins'])
def getPlayerAvgWR(self,ID):
u = Util()
return u.round3(float(self.getPlayerWins(ID))/float(self.getPlayerBattles(ID))*100)
def getPlayerAvgDmg(self,ID):
data = self.getPlayerStats(ID)
battles = self.getPlayerBattles(ID)
u = Util()
temp = float(data['pvp']['damage_dealt'])/float(battles)
return u.round2(temp)
def getPlayerAvgKills(self,ID):
data = self.getPlayerStats(ID)
battles = self.getPlayerBattles(ID)
u = Util()
temp = float(data['pvp']['frags'])/float(battles)
return u.round3(temp)
def getPlayerAvgSpottingDmg(self,ID):
data = self.getPlayerStats(ID)
battles = self.getPlayerBattles(ID)
u = Util()
temp = float(data['pvp']['damage_scouting'])/float(battles)
return u.round2(temp)
def getPlayerAvgPotentialDmg(self,ID):
data = self.getPlayerStats(ID)
battles = self.getPlayerBattles(ID)
u = Util()
temp = float(data['pvp']['torpedo_agro']+data['pvp']['art_agro'])/float(battles)
return u.round2(temp)
# PLAYER RELATED FUNCTIONS
# SHIP RELATED FUNCTIONS
def getPlayerShipStats(self,pID):
data={'application_id':self.ID,'account_id':pID}
r = requests.post(self.shipstatep,data)
try:
return json.loads(r.text)['data'][str(pID)]
except:
return None
def getShipName(self,ID):
data={'application_id':self.ID,'ship_id':ID}
r = requests.post(self.pediaep,data)
if json.loads(r.text)['data'][str(ID)] is not None:
out = json.loads(r.text)['data'][str(ID)]['name']
print(out)
return out
else:
pass
def getShipDmg(self,data):
return float(data['pvp']['damage_dealt'])
def getShipWR(self,data):
if(data['pvp']['wins']==0 or data['pvp']['battles']==0):
return 0.0
return float(data['pvp']['wins']/data['pvp']['battles']*100)
def getShipWins(self,data):
if(data['pvp']['wins']==0 or data['pvp']['battles']==0):
return 0.0
return int(data['pvp']['wins'])
def getShipKills(self,data):
return float(data['pvp']['frags'])
def getShipBattles(self,data):
return int(data['pvp']['battles'])
def getShipID(self,data):
return int(data['ship_id'])
# SHIP RELATED FUNCTIONS
# CLAN RELATED FUNCTIONS
def getClanID(self,name):
data={'application_id':self.ID,'search':name.strip()}
r = requests.post(self.clanlistep,data)
try:
return json.loads(r.text)['data'][0]['clan_id']
except:
return None
def getClanTag(self,ID):
data={'application_id':self.ID,'clan_id':ID}
r = requests.post(self.claninfoep,data)
try:
return json.loads(r.text)['data'][str(ID)]['tag']
except:
return None
def getClanName(self,ID):
data={'application_id':self.ID,'clan_id':ID}
r = requests.post(self.claninfoep,data)
try:
return json.loads(r.text)['data'][str(ID)]['name']
except:
return None
def getClanMembers(self,ID):
data={'application_id':self.ID,'clan_id':ID}
r = requests.post(self.claninfoep,data)
try:
return json.loads(r.text)['data'][str(ID)]['members_ids']
except:
return None
# CLAN RELATED FUNCTIONS
# OTHER
def expectedValues(self):
r = requests.get(self.wowsnumep)
data = json.loads(r.text)
return data
if(__name__=="__main__"):
a = API()
#print(a.ID)
#print(a.getClanID('MIA-E'))
#print(a.getClanTag('1000044001'))
#print(a.getClanName('1000044001'))
#print(a.getPlayerStats(a.getPlayerID('Modulatus')))
#print(a.getShipName(4287510224))
print(a.expectedValues())
print(a.getPlayerAvgSpottingDmg(a.getPlayerID("Modulatus")))
print(a.getPlayerAvgPotentialDmg(a.getPlayerID("Modulatus")))