-
Notifications
You must be signed in to change notification settings - Fork 0
/
count.py
47 lines (38 loc) · 1.54 KB
/
count.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
#!/usr/bin/python
import os
import os.path
import re
import sys
import json
from helpers import *
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
# got resource_path from http://stackoverflow.com/a/13790741
with open(resource_path('helpers/wot-maps.json'), 'rb') as data_file:
jsonData = json.load(data_file)
files = [name for name in os.listdir('.') if os.path.isfile(name) and not
name.startswith('temp') and name.endswith('.wotreplay')]
if len(files) > 0:
print "%-35s %s" % ("Number of replays processed:\t", len(files))
print "\n"
nameRegex = r"(\d+)\_\d+\_(.*)\_(\d+\_\D+)\.wotreplay"
maps = []
for replays in files:
replay = re.match(nameRegex, replays).groups()
maps.append(replay[2])
for count, mapName in sorted(((maps.count(e), e) for e in set(maps)),
reverse=True):
try:
print "%-35s %5s" % (jsonData["maps"][mapName], count)
except:
print "\nThese maps are not present in %s patch\n" % jsonData["_patch"]
print "%-35s %5s" % (mapName, count)
else:
print "There are no replays available for processing...\n" \
"Are you sure that you have enabled replay recording?"