feat: Get latest note with kanji and update its info

It's not being created as of now
This commit is contained in:
Dendy 2025-04-08 22:10:05 +02:00
parent 7333c5164d
commit 605d65e468
2 changed files with 29 additions and 3 deletions

View File

@ -180,8 +180,11 @@ class CreateProductionCommand extends Command
} }
printf(" OK\n"); printf(" OK\n");
asort($termCounts); $theChosenTerm = null;
arsort($termCounts);
printf("\n");
foreach ($termCounts as $term => $count) { foreach ($termCounts as $term => $count) {
$theChosenTerm = $knownTerms[$term];
$termKanji = self::getOnlyKanji($term); $termKanji = self::getOnlyKanji($term);
printf("%s: %d\n", $term, $count); printf("%s: %d\n", $term, $count);
@ -192,15 +195,33 @@ class CreateProductionCommand extends Command
} }
printf("\n"); printf("\n");
} break;
};
dump(count($termCounts)); $noteIds = $this->ankiService->findNotesIds(sprintf(
//'VocabKanji:*%s* "note:%s"',
'*%s* "note:%s"',
$theChosenTerm->getKanji(),
SentenceNote::MODEL_NAME,
));
$theChosenNote = $this->ankiService->getNote($noteIds[array_key_last($noteIds)]);
$fields = $theChosenNote->getFields();
$fields['VocabKanji'] = $theChosenTerm->getKanji();
$fields['VocabFurigana'] = $theChosenTerm->getReading();
$fields['VocabDef'] = $theChosenTerm->toAnkiVocabDef();
$fields['SentKanji'] = strip_tags($fields['SentKanji']);
$theChosenNote->setFields($fields);
dd($theChosenTerm->toAnkiVocabDef(), $theChosenNote->getFields());
printf( printf(
<<<FMNT <<<FMNT
total: %d cards
max usage: %0.2f MiB max usage: %0.2f MiB
current usage: %0.2f MiB\n current usage: %0.2f MiB\n
FMNT, FMNT,
count($termCounts),
memory_get_peak_usage() / 1024 / 1024, memory_get_peak_usage() / 1024 / 1024,
memory_get_usage() / 1024 / 1024, memory_get_usage() / 1024 / 1024,
); );

View File

@ -32,6 +32,11 @@ class AnkiService
return $result; return $result;
} }
public function findNotesIds(string $query): array
{
return $this->request('findNotes', ['query' => $query]);
}
public function getAllSentenceListeningNoteIds(): array public function getAllSentenceListeningNoteIds(): array
{ {
$query = sprintf( $query = sprintf(