-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_init.py
54 lines (46 loc) · 1.47 KB
/
web_init.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
import glob
import json
import pandas as pd
import os
def create_resultcsv():
txt = "static/category.csv"
if os.path.exists(txt):
print("%s exists" % txt)
return
with open(txt, "w") as out_f:
out_f.write("page_id,form_id,typetext_id,value,deleted,done\n")
jpgs = glob.glob("static/data/**/*.jpg")
for jpg in sorted(jpgs):
page_id, form_id = jpg.replace("static/data/", "").replace(".jpg", "").split("/")
form_id = int(form_id)
# print(page_id, form_id)
with open(jpg.replace(".jpg", "_texts.json")) as f:
d = json.load(f)
assert type(d) == dict
assert type(d["typeTexts"]) == list
for k in d["typeTexts"]:
typetext_id = k["index"]
print(page_id, form_id, typetext_id)
out_f.write("%s,%d,%d,%s,%s,%s\n" % (page_id, form_id, typetext_id, "{{未設定}}", False, False))
assert pd.read_csv(txt) is not None
def translate_format():
names = glob.glob("static/data/*/*_texts.json")
print(names)
for name in names:
rects = []
with open(name) as f:
d = json.load(f)
type_texts = d["typeTexts"]
form_rect = d["form"]["rect"]
for tt in type_texts:
# print(tt["rect"])
rect = tt["rect"]
rect["x"] -= form_rect["x"]
rect["y"] -= form_rect["y"]
rects.append(rect)
print(rects)
with open(name.replace("_texts.json", ".json"), "w") as f:
json.dump(rects, f, indent=2)
if __name__ == "__main__":
create_resultcsv()
translate_format()