sub processor
This commit is contained in:
parent
f7d3e366f0
commit
2c4d95fb8d
|
|
@ -98,6 +98,85 @@ def term_entries(term :str) -> dict:
|
|||
response = requests.post(request_url + "/termEntries", json = params, timeout = request_timeout)
|
||||
return json.loads(response.text)
|
||||
|
||||
ANKI_URL = "http://127.0.0.1:8765"
|
||||
|
||||
def request_anki(action, params=None):
|
||||
"""Sends a payload to AnkiConnect."""
|
||||
payload = {"action": action, "version": 6, "params": params or {}}
|
||||
response = requests.post(ANKI_URL, json=payload)
|
||||
response.raise_for_status()
|
||||
return response.json().get("result")
|
||||
|
||||
def get_card_proficiency(query="deck:current"):
|
||||
"""
|
||||
Finds cards by query, retrieves scheduling data,
|
||||
and prints proficiency stats for each card.
|
||||
"""
|
||||
card_ids = request_anki("findCards", {"query": query})
|
||||
if not card_ids:
|
||||
print("No cards found.")
|
||||
return
|
||||
|
||||
card_info = request_anki("cardsInfo", {"cards": card_ids})
|
||||
|
||||
card_proficiency = {}
|
||||
|
||||
for card in card_info:
|
||||
card_id = card["cardId"]
|
||||
# In Anki: 0=new, 1=learning, 2=review, 3=relearning
|
||||
queue_state = card["queue"]
|
||||
interval = card["interval"]
|
||||
reps = card["reps"]
|
||||
lapses = card["lapses"]
|
||||
|
||||
# Anki queue mappings:
|
||||
# 0 = New, 1 = Learning, 2 = Review, 3 = Relearning
|
||||
if queue_state == 0:
|
||||
status = "New"
|
||||
color = ''
|
||||
elif queue_state == 1:
|
||||
status = "Learning"
|
||||
color = 'orangered'
|
||||
elif queue_state == 3:
|
||||
status = "Relearning"
|
||||
color = 'yellow'
|
||||
elif queue_state == 2:
|
||||
# Review card split by 21-day threshold
|
||||
if interval >= 21:
|
||||
status = "Mature"
|
||||
color = 'cyan'
|
||||
else:
|
||||
status = "Young"
|
||||
color = 'lime'
|
||||
elif queue_state < 0:
|
||||
status = "Suspended"
|
||||
color = ''
|
||||
else:
|
||||
status = f"Unknown (Queue {queue})"
|
||||
color = ''
|
||||
|
||||
word = ''
|
||||
if (card['fields'].get('Word')):
|
||||
print(card['fields']['Word'])
|
||||
word = card['fields']['Word']['value']
|
||||
else:
|
||||
#print(card['fields'])
|
||||
continue
|
||||
|
||||
if (card_proficiency.get(word)):
|
||||
print("Multiple matches for word")
|
||||
else:
|
||||
card_proficiency[word] = {'Status' : status,'State' : status, 'Color' : color}
|
||||
|
||||
print(f"Card ID {card_id} (State: {queue_state}):")
|
||||
print(f" Reps: {reps} | Lapses: {lapses} | Interval: {interval} days | Ease: {status} \n")
|
||||
|
||||
return card_proficiency
|
||||
|
||||
# Example usage: Evaluate proficiency for all cards in a specific deck
|
||||
# get_card_proficiency(query='deck:"Your Deck Name Here"')
|
||||
proficiency_stats = get_card_proficiency(query='deck:"Japanese Vocab" card:0')
|
||||
|
||||
CONTENT_LINK_TAG = {
|
||||
'名詞': 'meishi', # noun
|
||||
'動詞': 'doshi', # verb
|
||||
|
|
@ -141,6 +220,20 @@ def build_ruby(surface: str, reading: str) -> str:
|
|||
return html.escape(surface)
|
||||
return f"<ruby>{html.escape(surface)}<rt>{html.escape(reading)}</rt></ruby>"
|
||||
|
||||
def build_sub_cue(surface: str, reading: str) -> str:
|
||||
if not reading or not has_japanese(surface):
|
||||
return html.escape(surface)
|
||||
# Check if color
|
||||
color_prefix = ''
|
||||
color_suffix = ''
|
||||
if proficiency_stats.get(surface):
|
||||
if proficiency_stats[surface]['Color'] != '':
|
||||
color_prefix = f"<c.{proficiency_stats[surface]['Color']}>"
|
||||
color_suffix = f"</c>"
|
||||
if surface == reading:
|
||||
return f"{color_prefix}{html.escape(surface)}{color_suffix}"
|
||||
return f"{color_prefix}<ruby>{html.escape(surface)}<rt>{html.escape(reading)}</rt></ruby>{color_suffix}"
|
||||
|
||||
def build_kana(surface: str, reading: str) -> str:
|
||||
if not reading or surface == reading or not has_japanese(surface):
|
||||
return surface
|
||||
|
|
|
|||
|
|
@ -83,16 +83,20 @@ def main():
|
|||
i+=1
|
||||
|
||||
## Lookup vocab
|
||||
for word in vocab:
|
||||
write_word_note(word, destination_path)
|
||||
return
|
||||
try:
|
||||
for word in vocab:
|
||||
write_word_note(word, destination_path)
|
||||
except:
|
||||
print("Unable to word lookup")
|
||||
## Dammit
|
||||
# return
|
||||
|
||||
# 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')
|
||||
changed_file = out_dir.joinpath(Path(args.subtitle_file).stem + '-ruby.vtt')
|
||||
with open(changed_file, "w", encoding="utf-8") as f:
|
||||
f.writelines(lines)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user