-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
67 lines (55 loc) · 1.74 KB
/
main.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
import json
from os.path import join, isfile
from os import listdir
import os
final_file_name = "yourworldname.points"
def parse(filename):
try:
return json.load(filename)
except ValueError as e:
print('invalid json: %s' % e)
return "ERROR - %s \n\n" % e
def take_all_files(path):
onlyfiles = [ f for f in listdir(path) if isfile(join(path, f))]
print(onlyfiles)
percorsi = []
for file in onlyfiles:
if ".json" in file:
percorsi.append(str(path+"/"+file))
return percorsi
def get_dimensions(dimensions):
stringa=""
for dimension in dimensions:
stringa+=str(dimension)+"#"
return stringa
def main():
files = take_all_files("input")
filesJson =[]
for file in files:
with open(file) as f:
json_imported = parse(f)
filesJson.append(json_imported)
lines = []
lines.append("subworlds:\n")
lines.append("oldNorthWorlds:\n")
lines.append("seeds:\n")
for file in filesJson:
stringa = "name:"+ file['name']+","
stringa+=" x:" +str(file['x'])+","
stringa+=" z:" +str(file['z'])+","
stringa+=" y:" +str(file['y'])+","
stringa+="enabled:" +str(file['enable'])+","
stringa+=" red:" +"0.0,"
stringa+=" green:" +"0.0,"
stringa+=" blue:" +"0.0,"
stringa+="suffix:,"
stringa+="world:,"
stringa+="dimensions:"+get_dimensions(file['dimensions'])+"\n"
lines.append(stringa)
try:
os.mkdir("output")
except FileExistsError as e:
print("directory already exist")
file = open("output/"+final_file_name,"w+")
file.writelines(lines)
main()