sub processor accepts parameters
This commit is contained in:
parent
e2d0e08346
commit
3cd4e9279b
|
|
@ -38,7 +38,7 @@ def main():
|
||||||
file_changed = False
|
file_changed = False
|
||||||
while i < len(lines):
|
while i < len(lines):
|
||||||
## Skip lines that start with certain elements
|
## Skip lines that start with certain elements
|
||||||
if lines[i][0:6] == '<span>' or lines[i][0] in ('#','>'):
|
if lines[i][0:6] == '<span>' or lines[i][0] in ('#','>','['):
|
||||||
i+=1
|
i+=1
|
||||||
continue
|
continue
|
||||||
## If the line has japanese
|
## If the line has japanese
|
||||||
|
|
@ -57,24 +57,6 @@ def main():
|
||||||
## Lookup vocab
|
## Lookup vocab
|
||||||
for word in vocab:
|
for word in vocab:
|
||||||
write_word_note(word, destination_path)
|
write_word_note(word, destination_path)
|
||||||
# if Path(destination_path.joinpath('/' + word + '.md')).exists() == False:
|
|
||||||
# definitions = anki_fields_term(word)
|
|
||||||
# if definitions.get("fields"):
|
|
||||||
# with open(destination_path.as_posix() + '/' + word + '.md', 'w') as vocab_note:
|
|
||||||
# for entry in definitions.get("fields"):
|
|
||||||
# #vocab_note.write("\n")
|
|
||||||
# #print(entry['expression'], file=vocab_note)
|
|
||||||
# #print(entry['furigana-plain'], file=vocab_note)
|
|
||||||
# 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"Part of Speech: {entry['part-of-speech']}", file=vocab_note)
|
|
||||||
# print(f"Frequency: {entry['frequency-average-rank']}", file=vocab_note)
|
|
||||||
# #print(entry['glossary-plain-no-dictionary'], file=vocab_note)
|
|
||||||
# vocab_note.write(entry['glossary-first'])
|
|
||||||
# #print("##### Other Definitions", file=vocab_note)
|
|
||||||
# print("\n", file=vocab_note)
|
|
||||||
|
|
||||||
## Output file with changes if changes
|
## Output file with changes if changes
|
||||||
with open(args.markdown_file, "w", encoding="utf-8") as f:
|
with open(args.markdown_file, "w", encoding="utf-8") as f:
|
||||||
|
|
|
||||||
|
|
@ -6,33 +6,48 @@ import shutil
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
destination_directory_name = '/run/media/deck/YF8SD/Sync/Notebooks/Obsidian/Japanese/Yu-Gi-Oh/AnimeSubs/'
|
# destination_directory_name = '/run/media/deck/YF8SD/Sync/Notebooks/Obsidian/Japanese/Yu-Gi-Oh/AnimeSubs/'
|
||||||
destination_path = Path(destination_directory_name)
|
# destination_path = Path(destination_directory_name)
|
||||||
|
|
||||||
dictionary_name = 'Jitendex.org [2026-04-04]'
|
# dictionary_name = 'Jitendex.org [2026-04-04]'
|
||||||
|
|
||||||
#print(annotate_phrase("私は学校へ行きます"))
|
# #print(annotate_phrase("私は学校へ行きます"))
|
||||||
|
|
||||||
## Make sure directories exist
|
# ## Make sure directories exist
|
||||||
if not destination_path.exists():
|
# if not destination_path.exists():
|
||||||
destination_path.mkdir(parents=True, exist_ok=True)
|
# destination_path.mkdir(parents=True, exist_ok=True)
|
||||||
if not destination_path.joinpath('_attachments').exists():
|
# if not destination_path.joinpath('_attachments').exists():
|
||||||
destination_path.joinpath('_attachments').mkdir(parents=True, exist_ok=True)
|
# destination_path.joinpath('_attachments').mkdir(parents=True, exist_ok=True)
|
||||||
if not destination_path.joinpath('vocab').exists():
|
# if not destination_path.joinpath('vocab').exists():
|
||||||
destination_path.joinpath('vocab').mkdir(parents=True, exist_ok=True)
|
# destination_path.joinpath('vocab').mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
# ---------- CLI ----------
|
# ---------- CLI ----------
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
# parser.add_argument("--vocab-file", required=True)
|
#parser.add_argument("--vocab-file", required=True)
|
||||||
# parser.add_argument("text", nargs="*")
|
parser.add_argument("--subtitle-file", required=True)
|
||||||
# args = parser.parse_args()
|
parser.add_argument("--vocab-folder", required=False)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
vocab = load_vocab('foo.json')
|
if args.vocab_folder:
|
||||||
|
destination_path = Path(args.vocab_folder)
|
||||||
|
if destination_path.is_dir() == False:
|
||||||
|
raise ValueError("Vocab Folder is not a directory.")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
destination_path = Path(args.subtitle_file).parent
|
||||||
|
if not destination_path.joinpath('vocab').exists():
|
||||||
|
destination_path.joinpath('vocab').mkdir(parents=True, exist_ok=True)
|
||||||
|
destination_path = destination_path.joinpath('vocab')
|
||||||
|
|
||||||
with open("/run/media/deck/YF8SD/Video/Yu-Gi-Oh! Duel Monsters - 001.vtt", "r", encoding="utf-8") as f:
|
# with open("/run/media/deck/YF8SD/Video/Yu-Gi-Oh! Duel Monsters - 001.vtt", "r", encoding="utf-8") as f:
|
||||||
|
# lines = f.readlines()
|
||||||
|
vocab = {} #load_vocab('foo.json')
|
||||||
|
|
||||||
|
## Currently just doing this line by line
|
||||||
|
with open(args.subtitle_file, "r", encoding="utf-8") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -64,32 +79,21 @@ def main():
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
## Lookup vocab
|
## Lookup vocab
|
||||||
if False:
|
for word in vocab:
|
||||||
for word in vocab:
|
write_word_note(word, destination_path)
|
||||||
#vocab_hash = hashlib.shake_256((word + dictionary_name).encode()).hexdigest(4)
|
|
||||||
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"):
|
|
||||||
vocab_note.write("\n")
|
|
||||||
print(entry['expression'], file=vocab_note)
|
|
||||||
#print(entry['furigana-plain'], file=vocab_note)
|
|
||||||
if entry['expression'] != entry['reading']:
|
|
||||||
print(entry['reading'], file=vocab_note)
|
|
||||||
print(entry['furigana'], file=vocab_note)
|
|
||||||
#print(f"Part of Speech: {entry['part-of-speech']}", file=vocab_note)
|
|
||||||
print(f"Frequency: {entry['frequency-average-rank']}", file=vocab_note)
|
|
||||||
#print(entry['glossary-plain-no-dictionary'], file=vocab_note)
|
|
||||||
vocab_note.write(entry['glossary-first'])
|
|
||||||
print("##### Other Definitions", file=vocab_note)
|
|
||||||
print(entry['glossary-plain-no-dictionary'], file=vocab_note)
|
|
||||||
|
|
||||||
with open("/run/media/deck/YF8SD/Video/Yu-Gi-Oh! Duel Monsters - 001.vtt", "w", encoding="utf-8") as f:
|
# with open("/run/media/deck/YF8SD/Video/Yu-Gi-Oh! Duel Monsters - 001.vtt", "w", encoding="utf-8") as f:
|
||||||
|
# f.writelines(lines)
|
||||||
|
|
||||||
|
## Output file with changes if changes
|
||||||
|
out_dir = Path(args.subtitle_file).parent
|
||||||
|
changed_file = out_dir.joinpath(Path(args.subtitle_file).stem + '.txt')
|
||||||
|
with open(changed_file, "w", encoding="utf-8") as f:
|
||||||
f.writelines(lines)
|
f.writelines(lines)
|
||||||
|
|
||||||
# with open("notestest-newchunks.md", "w", encoding="utf-8") as f:
|
note_file = out_dir.joinpath(Path(args.subtitle_file).stem + '.md')
|
||||||
# f.writelines(notes_lines)
|
with open(note_file, "w", encoding="utf-8") as f:
|
||||||
|
f.writelines(notes_lines)
|
||||||
|
|
||||||
#vocab = load_vocab(args.vocab_file)
|
#vocab = load_vocab(args.vocab_file)
|
||||||
#result = analyze(text, vocab)
|
#result = analyze(text, vocab)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user