1
|
|
|
import os |
2
|
|
|
import glob |
3
|
|
|
import zipfile |
4
|
|
|
import tkinter.filedialog as filedialog |
5
|
|
|
import shutil |
6
|
|
|
import tkinter.ttk as ttk |
7
|
|
|
import tkinter as tk |
8
|
|
|
|
9
|
|
|
tree_folder = [ |
10
|
|
|
["data/character", "キャラクター"], |
11
|
|
|
["data/occupation", "職種"], |
12
|
|
|
["data/space", "場所"], |
13
|
|
|
["data/event", "イベント"], |
14
|
|
|
["data/nobel", "小説"], |
15
|
|
|
] |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
def sub_name_OK(): |
19
|
|
|
fTyp = [("小説エディタ", ".ned")] |
20
|
|
|
iDir = os.path.abspath(os.path.dirname(__file__)) |
21
|
|
|
filepath = filedialog.askopenfilename(filetypes=fTyp, initialdir=iDir) |
22
|
|
|
# ファイル名があるとき |
23
|
|
|
if not filepath == "": |
24
|
|
|
with zipfile.ZipFile(filepath) as existing_zip: |
25
|
|
|
existing_zip.extractall("./data") |
26
|
|
|
|
27
|
|
|
for val in tree_folder: |
28
|
|
|
files = glob.glob("{0}/*".format(val[0])) |
29
|
|
|
for file in files: |
30
|
|
|
f = open(file, "r", encoding="shift-jis") |
31
|
|
|
text_text = f.read() |
32
|
|
|
f.close() |
33
|
|
|
if val[0] == tree_folder[0][0]: |
34
|
|
|
title, ___ = os.path.splitext(os.path.basename(file)) |
35
|
|
|
text_text = '<?xml version="1.0"?>\n<data>\n\t<call>{0}</call>\n\t<name></name>\n\t<sex>0</sex>\n\t<birthday></birthday>\n\t<body>{1}</body>\n</data>'.format( |
36
|
|
|
title, text_text |
37
|
|
|
) |
38
|
|
|
f = open(file, "w", encoding="utf-8") |
39
|
|
|
f.write(text_text) |
40
|
|
|
f.close() |
41
|
|
|
shutil.make_archive(filepath, "zip", "./data") |
42
|
|
|
# 拡張子の変更を行う |
43
|
|
|
shutil.move("{0}.zip".format(filepath), "{0}".format(filepath)) |
44
|
|
|
label1 = tk.Label(root, text="変換終了") |
45
|
|
|
label1.grid(row=1, column=0) |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
root = tk.Tk() |
49
|
|
|
button = ttk.Button( |
50
|
|
|
root, text="変換", width=str("変換"), padding=(10, 5), command=sub_name_OK |
51
|
|
|
) |
52
|
|
|
button.grid(row=0, column=0) |
53
|
|
|
root.mainloop() |
54
|
|
|
|