-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathminecraft leader board 3.0.py
245 lines (217 loc) · 7.73 KB
/
minecraft leader board 3.0.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
from os import walk
import requests
import os
from json import *
from urllib.request import *
import urllib
from time import sleep
import pickle
def save_obj(obj, name ):
with open('obj/'+ name + '.pkl', 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
def load_obj(name ):
with open('obj/' + name + '.pkl', 'rb') as f:
return pickle.load(f)
players=[]
try:
uuids=load_obj("uuid")
except:
uuids={}
stats=dict()
class StatPare:
def __init__(self,name,value):
self.name=name
self.value=value
def __str__(self):
return str(self.name)+": "+str(self.value)
class Stat:
def __init__(self,name,value,player):
self.name=name
self.minPlr=[player]
self.maxPlr=[player]
self.maxV=value
self.minV=value
def min(self,other,name):
if(self.minV>other):
self.minV=other
self.minPlr=[name]
elif self.minV==other:
self.minPlr.append(name)
def max(self,other,name):
if(self.maxV<other):
self.maxV=other
self.maxPlr=[name]
elif self.maxV==other:
self.maxPlr.append(name)
def __str__(self):
return "Most: "+self.name+": "+str(self.maxV)+" "+str(self.maxPlr)+"\nLeast: "+self.name+": "+str(self.minV)+" "+str(self.minPlr)
#stats.append(Stat("generic",0,"none"))
globalStats =dict()
class Player:
def __init__(self,uuid):
self.score=0;
self.name="Useful Minecraft Resources"
if uuid in uuids:
self.name=uuids[uuid]
else:
self.name=uuid_api(uuid)
uuids[uuid]=self.name
save_obj(uuids,"uuid")
self.uuid=uuid
self.stats=dict()
if self.name=="Useful Minecraft Resources":
print(uuid)
#print(page)
print("UUID: "+uuid+" Name: "+self.name)
def mcuuid(self,uuid):
i=0
while(self.name=="Useful Minecraft Resources" and i<5):
page = urlopen(Request("http://mcuuid.net/?q="+uuid,headers={'User-Agent' : "Magic Browser"}))
page=str(page.read());
start=page.find("<h3 id=\"results_username\">")
start=page.find(">",start)
end=page.find("</h3>")
self.name=page[start+4:end]
#page=page[0:start]+page[end+5:-1]
sleep(2)
i+=1
print("index: "+str(i))
if i>=5:
self.name="[MISSING] UUID= "+uuid
def namemc(self, uuid):
try:
while True:
page = urlopen(Request("http://namemc.com/profile/"+uuid,headers={'User-Agent' : "Magic Browser"}))
page=str(page.read());
start=page.find("<h1")
end=page.find("</h1>")
start=page.find(">",start)
self.name=page[start:end]
#print(self.name)
self.name=self.name[self.name.find('>')+1:]
#print (len(self.name))
if len(self.name)>1:
break
sleep(10)
#print(self.name)
#page=page[0:start]+page[end+5:-1]
except:
self.mcuuid(uuid)
sleep(5)
def __str__(self):
return self.name
def uuid_api(uuid):
page = requests.get("https://api.mojang.com/user/profiles/"+uuid.replace("-","")+"/names")
page=page.json()
name=""
lastTime=-1
for line in page:
#print (line)
time=0
if "changedToAt" in line:
time=line["changedToAt"]
if time>lastTime:
name=line["name"]
lastTime=time
return name
def extract(path,name):
if(".json" in name):
player=Player(name[0:name.find('.')])
if(len(player.name)>2):
players.append(player);
stringin=open (path,'r')
jsonIn=loads(stringin.read())["stats"]
players[-1].stats={}
for key in jsonIn.keys():
holdString=key;
for subkey in jsonIn[key].keys():
tmpstr=subkey.replace("minecraft","")
players[-1].stats[(holdString+tmpstr).replace(':','.')]=jsonIn[key][subkey]
def dirin(mypath):
for (dirpath, dirnames, filenames) in walk(mypath):
for path in dirnames:
dirin(dirpath+'/'+path)
for path in filenames:
extract(dirpath+'/'+path,path)
break
path=input("Path directory to be checked: ")
print("looking up UUID's, this can take quite some time")
dirin(path)
print("Creating top and bottom summary list")
fullStats=dict()
for player in players:
for key in player.stats:
#for i in stats:
if (key in fullStats):
fullStats[key].append(StatPare(player.name,player.stats[key]))
else:
fullStats[key]=[]
fullStats[key].append(StatPare(player.name,player.stats[key]))
if (key in stats):
if key in globalStats:
globalStats[key]+=player.stats[key]
else:
globalStats[key]=player.stats[key];
stats[key].max(player.stats[key],player.name)
stats[key].min(player.stats[key],player.name)
else:
stats[key]=Stat(key,player.stats[key],player.name)
file=open(path+"/Leader Board.txt",'w')
for key in stats:
#print (stats[key])
file.write("\n"+str(stats[key]))
print("wrote summary to "+path+"/Leader Board.txt")
file.close()
print("Writing names of all players")
file=open(path+"/Names.txt",'w')
playerList=[]
for player in players:
file.write("\n"+str(player))
players.sort(key=lambda x: x.name,reverse=False)
file.close()
file=open(path+"/total.txt",'w')
print("Writing total for each stat")
index=0
statList=[]
for key in globalStats:
file.write("\n"+str(key)+": "+str(globalStats[key]))
statList.append(key)
statList.sort(key=lambda x: x,reverse=False)
for stat in statList:
index+=1
print(statList)
file.close()
print("writing comprehensive summary of each stat")
for key in fullStats:
fullStats[key].sort(key=lambda x: x.value,reverse=True)
#print(key)
if not os.path.exists(path+"/full"):
os.makedirs(path+"/full")
file=open(path+"/full/"+key+".txt",'w+')
c=0
total=0
for p in fullStats[key]:
c+=1
file.write(str(c)+": "+str(p)+"\n")
total+=p.value
file.write("Total "+ str(total))
file.close()
print("Finished writing comprehensive summary, it is avaliable in "+path+"\\full")
save_obj(uuids,"uuid")
save_obj(players,"players")
print("Working on comprehensive csv")
file=open(path+"/stats.csv","w")
header="Player Name"
for stat in statList:
header+=","+stat
file.write(header+"\n")
for player in players:
line=player.name
for stat in statList:
if stat in player.stats:
line+=","+str(player.stats[stat])
else:
line+=",0"
file.write(line+"\n")
file.close()
print("Finished")