|
import os
|
|
import json
|
|
import sys
|
|
|
|
EXTRA_FILE = "ponyDiffusionV6XL_LoRAReadme.txt"
|
|
|
|
class Section:
|
|
def __init__(self, title, trigger, content):
|
|
self.title = title
|
|
self.trigger = trigger
|
|
self.content = content
|
|
|
|
def write_to_file(self):
|
|
filename = f"{self.title}.txt"
|
|
if filename == "このファイルについて.txt":
|
|
pass
|
|
elif not os.path.exists(filename):
|
|
with open(filename, 'w', encoding='utf-8-sig') as file:
|
|
file.write(self.content)
|
|
print(f"{section.title}.txtと{section.title}.jsonを出力しました")
|
|
else:
|
|
pass
|
|
|
|
|
|
def write_to_json(self):
|
|
filename = f"{self.title}.json"
|
|
if filename == "このファイルについて.json":
|
|
pass
|
|
elif not os.path.exists(filename):
|
|
data = {
|
|
"description": self.content,
|
|
"sd version": "SDXL",
|
|
"activation text": self.trigger,
|
|
"preferred weight": 0,
|
|
"negative text": "",
|
|
"notes": ""
|
|
}
|
|
with open(filename, 'w', encoding='utf-8') as file:
|
|
json.dump(data, file, ensure_ascii=False, indent=4)
|
|
else:
|
|
pass
|
|
|
|
|
|
def extract_sections(filename):
|
|
sections = {}
|
|
with open(filename, 'r', encoding='utf-8') as file:
|
|
lines = file.readlines()
|
|
|
|
current_title = ""
|
|
current_trigger = ""
|
|
current_content = []
|
|
inside_section = False
|
|
|
|
for line in lines:
|
|
stripped_line = line.strip()
|
|
|
|
if stripped_line.startswith('■'):
|
|
if inside_section:
|
|
sections[current_title] = Section(current_title, current_trigger, "\n".join(current_content))
|
|
current_title = stripped_line[1:].strip()
|
|
current_trigger = ""
|
|
current_content = []
|
|
inside_section = True
|
|
elif "で呼び出し" in stripped_line:
|
|
current_trigger = stripped_line.replace("で呼び出し", "").strip()
|
|
current_content.append(stripped_line)
|
|
elif stripped_line == "":
|
|
if inside_section:
|
|
sections[current_title] = Section(current_title, current_trigger, "\n".join(current_content))
|
|
current_title = ""
|
|
current_trigger = ""
|
|
current_content = []
|
|
inside_section = False
|
|
else:
|
|
current_content.append(stripped_line)
|
|
|
|
if inside_section:
|
|
sections[current_title] = Section(current_title, current_trigger, "\n".join(current_content))
|
|
|
|
return sections
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
try:
|
|
sections = extract_sections(EXTRA_FILE)
|
|
except:
|
|
print(f"{EXTRA_FILE}が存在しません。")
|
|
sys.exit()
|
|
|
|
for title, section in sections.items():
|
|
section.write_to_file()
|
|
section.write_to_json()
|
|
|