dialog extract note creation script added
This commit is contained in:
parent
acd17c2cbb
commit
5cc5985e91
92
make_dialog_notes.py
Normal file
92
make_dialog_notes.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
from fugashi_parser import *
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import hashlib
|
||||
|
||||
destination_directory_name = '/run/media/deck/YF8SD/Sync/Notebooks/Obsidian/Japanese/Yu-Gi-Oh/'
|
||||
destination_path = Path(destination_directory_name)
|
||||
|
||||
with open("scripts_dump2.json", "r", encoding="utf-8") as f:
|
||||
dump = json.load(f)
|
||||
|
||||
if not destination_path.exists():
|
||||
destination_path.mkdir(parents=True, exist_ok=True)
|
||||
if not destination_path.joinpath('YLOTD_dialog').exists():
|
||||
destination_path.joinpath('YLOTD_dialog').mkdir(parents=True, exist_ok=True)
|
||||
|
||||
counter = 0
|
||||
destination_path = destination_path.joinpath('YLOTD_dialog')
|
||||
for title in dump:
|
||||
print(title)
|
||||
counter+=1
|
||||
## copy the image if it isn't already there
|
||||
with open(destination_path.as_posix() + f"/{counter:03}_{title}.md", 'w') as card_note:
|
||||
for block in dump[title]:
|
||||
print(block)
|
||||
card_note.write(f"\n###### {block}\n\n")
|
||||
#reformatted = re.sub(r'(\d{2})/(\d{2})/(\d{4})', r'\3-\1-\2', date)
|
||||
#re.replace('\$R')
|
||||
text_J = dump[title][block]['text_J']
|
||||
text_J = re.sub(r'\$R(.*?)\((.*?)\)',r'<ruby>\1<rt>\2</rt></ruby>',text_J)
|
||||
print(f"<details><summary>{text_J}</summary>{dump[title][block]['text_E']}</details>",file=card_note)
|
||||
# ## add card names as properties
|
||||
# card_note.write("---\n")
|
||||
# card_note.write(f"aliases: [{dump[cd]['name_J']},{dump[cd]['name_E']}]\n")
|
||||
# card_note.write("---\n")
|
||||
## Name at the top
|
||||
# card_note.write(f"![[{cd}.jpg]]") ## card image
|
||||
# card_note.write("\n#### Name\n")
|
||||
# card_note.write("<details><summary>")
|
||||
# card_note.write(dump[cd]['name_J'])
|
||||
# card_note.write("</summary>")
|
||||
# card_note.write(dump[cd]['name_E'])
|
||||
# card_note.write("</details>")
|
||||
# ## the description
|
||||
# card_note.write("\n#### Details\n")
|
||||
# card_note.write("<details><summary>")
|
||||
# card_note.write(dump[cd]['desc_J'])
|
||||
# card_note.write("</summary>")
|
||||
# card_note.write(dump[cd]['desc_E'])
|
||||
# card_note.write("</details>")
|
||||
# # desc_Furi
|
||||
# card_note.write("\n#### Reading\n")
|
||||
# vocab = {} ## flush the vocab variable each time
|
||||
# result = analyze(dump[cd]['name_J'],vocab)
|
||||
# print(f"<span>{result['ruby_html']}</span>\n> [!summary]- Vocab\n>{result['notes_link']}\n",file=card_note)
|
||||
# ## Generate the vocab item
|
||||
# for word in vocab:
|
||||
# if Path(destination_path.joinpath('vocab/' + word + '.md')).exists() == False:
|
||||
# definitions = anki_fields_term(word)
|
||||
# if definitions.get("fields"):
|
||||
# with open(destination_path.as_posix() + '/vocab/' + word + '.md', 'w') as vocab_note:
|
||||
# for entry in definitions.get("fields"):
|
||||
# print(entry['furigana'], file=vocab_note)
|
||||
# if entry['expression'] != entry['reading']:
|
||||
# print(entry['reading'], file=vocab_note)
|
||||
# print("> ",re.sub(r'<.*?>', '', entry['glossary-plain-no-dictionary']), "\n", file=vocab_note)
|
||||
# print(f"Frequency: {entry['frequency-average-rank']}", file=vocab_note)
|
||||
# vocab_note.write(entry['glossary-first'])
|
||||
# print("\n", file=vocab_note)
|
||||
# # card_note.write("##### Glossary\n")
|
||||
# # for vocab in dump[cd]["glossary_Name_J"]:
|
||||
# # print(f"{vocab} : {dump[cd]["glossary_Name_J"][vocab]}", file=card_note)
|
||||
# vocab = {} ## flush the vocab variable each time
|
||||
# result = analyze(dump[cd]['desc_J'],vocab)
|
||||
# #card_note.write("\n")
|
||||
# print(f"<span>{result['ruby_html']}</span>\n> [!summary]- Vocab\n>{result['notes_link']}\n",file=card_note)
|
||||
# for word in vocab:
|
||||
# if Path(destination_path.joinpath('vocab/' + word + '.md')).exists() == False:
|
||||
# definitions = anki_fields_term(word)
|
||||
# if definitions.get("fields"):
|
||||
# with open(destination_path.as_posix() + '/vocab/' + word + '.md', 'w') as vocab_note:
|
||||
# for entry in definitions.get("fields"):
|
||||
# print(entry['furigana'], file=vocab_note)
|
||||
# if entry['expression'] != entry['reading']:
|
||||
# print(entry['reading'], file=vocab_note)
|
||||
# print("> ",re.sub(r'<.*?>', '', entry['glossary-plain-no-dictionary']), "\n", file=vocab_note)
|
||||
# print(f"Frequency: {entry['frequency-average-rank']}", file=vocab_note)
|
||||
# vocab_note.write(entry['glossary-first'])
|
||||
# print("\n", file=vocab_note)
|
||||
# card_note.write("\n")
|
||||
Loading…
Reference in New Issue
Block a user