-
Notifications
You must be signed in to change notification settings - Fork 0
/
filefinder.bedrock.py
72 lines (67 loc) · 2.65 KB
/
filefinder.bedrock.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
# This filters the lang files from the default rp
import os
def rename(initname):
name=initname.replace('lang', "")
name=name+"json"
name=name.lower()
return name
for dirpath, dirnames, filenames in os.walk("texts"):
for file in filenames:
if file=="language_names.json":
os.replace(os.path.join(dirpath, file), file)
if ".lang" in file:
os.replace(os.path.join(dirpath, file), os.path.join("lang/bedrock", file)) # Places the lang files in the "lang/bedrock" folder. The "texts" one should be empty
print(file, "moved")
else:
os.remove(os.path.join(dirpath, file))
for dirpath, dirnames, filenames in os.walk("lang/bedrock"):
for file in filenames:
if ".json" not in file:
os.rename(f"{dirpath}/{file}", f"{dirpath}/{rename(file)}") # ... renames the file
print(f"{file} renamed into .json")
for dirpath, dirnames, filenames in os.walk("lang/bedrock"):
for file in filenames:
try:
f=open(os.path.join(dirpath, file), 'r+', encoding='utf-8').read()
f=f.split("\n")
for x in f:
old=x
#print(x)
try:
removefrom = lambda s, ss: s[:s.index(ss) + len(ss)]
x=removefrom(x, "#")
x=x.replace("#", "")
#print(x)
except ValueError: pass
if "=" in x:
y=x.split("=")
try:
a=y[2]
together=[y[1], y[2]]
y[1]="=".join(together)
del y[2]
except IndexError:pass
try:
a=y[2]
together=[y[1], y[2]]
y[1]="=".join(together)
del y[2]
except IndexError:pass
for z in y:
oldz=z
z=z.replace("\t", "")
z=z.replace('\\', "\\"+"\\")
z=z.replace('"', r'\"')
y[y.index(oldz)]='"'+z+'"'
f[f.index(old)]=":".join(y)
x=":".join(y)
#print(x)
else:pass
f = [line for line in f if "#" not in line]
f = list(filter(("").__ne__, f))
f = list(filter((" ").__ne__, f))
f = "{"+",\n".join(f)+"}"
open(os.path.join(dirpath, file), "r+", encoding='utf-8').write(f)
#print(f)
except UnicodeDecodeError:pass
print("Done.")