forked from tritonas00/RoRServerBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cr_dict.py
44 lines (33 loc) · 1.07 KB
/
cr_dict.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
import os
import zipfile
rootdir = './'
list = {}
def getExtension(filename):
return filename.split('.').pop()
def getFirstLine(file):
return file.readlines()[0].strip()
def getFilename(path):
return path.split('/').pop()
for subdir, dirs, files in os.walk(rootdir):
for file in files:
ext = getExtension(file)
if ext == "zip":
try:
z = zipfile.ZipFile(file)
except zipfile.BadZipfile:
continue
for f in z.namelist():
ext_zip = getExtension(f)
if ext_zip in ['truck', 'trailer', 'airplane', 'boat', 'load']:
list[getFilename(f)] = getFirstLine(z.open(f))
z.close()
elif ext in ['truck', 'trailer', 'airplane', 'boat', 'load']:
f = open(file, 'r')
list[getFilename(file)] = getFirstLine(f)
f.close()
output = open('output.txt', 'w')
output.write("list = {\n")
for filename in list:
output.write(" '%s': '%s',\n" % (filename, list[filename]))
output.write("}")
output.close()