-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickJSON.py
More file actions
executable file
·47 lines (33 loc) · 1.11 KB
/
QuickJSON.py
File metadata and controls
executable file
·47 lines (33 loc) · 1.11 KB
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/env python3
import json
import os
import re
import shutil
images = []
imageFolderPath = "Tiles_TBP/"
imageFiletype = ".png"
def createJSONForTiles(destinationPath):
directoryPath = imageFolderPath + destinationPath
for image in os.listdir(directoryPath):
images.append(os.path.join(directoryPath, image))
with open("tile_template.json", "r") as read_file:
template = json.load(read_file)
for image in images:
print("Processing " + image)
pathRegex = '(?<=' + directoryPath + ')(.*).png'
try:
id = re.findall(pathRegex, image)[0]
print("Creating " + id + " json")
template["id"] = id
template["fg"] = id
jsonPath = destinationPath + id + ".json"
with open(jsonPath, 'a+') as outfile:
json.dump(template, fp=outfile)
imageSource = directoryPath + id + imageFiletype
shutil.move(imageSource, destinationPath)
except:
print("Skip")
large = "Large_20x20/"
small = "Small_10x10/"
createJSONForTiles(large)
createJSONForTiles(small)