Migrated links, lyrics and properties

This commit is contained in:
marc
2025-03-23 21:46:04 +01:00
parent c097811e40
commit d596861a2e
47 changed files with 1403 additions and 844 deletions

View File

@@ -2,21 +2,16 @@ import datetime
import json
from typing import TypedDict
from folkugat_web.model import IndexedList
from folkugat_web.model import search as search_model
from folkugat_web.model import temes as model
TemaRowTuple = tuple[int, str, str, str, str, str, str, str, str, int]
TemaRowTuple = tuple[int, str, str, str, str, int]
class TemaRowDict(TypedDict):
id: int | None
title: str
properties: str
links: str
lyrics: str
alternatives: str
ngrams: str
modification_date: str
creation_date: str
hidden: int
@@ -26,31 +21,24 @@ def tema_to_row(tema: model.Tema) -> TemaRowDict:
return {
'id': tema.id,
'title': tema.title,
'properties': json.dumps(list(map(lambda p: p.to_dict(), tema.properties))),
'links': json.dumps(list(map(lambda l: l.to_dict(), tema.links))),
'lyrics': json.dumps(list(map(lambda l: l.to_dict(), tema.lyrics))),
'alternatives': json.dumps(tema.alternatives),
'ngrams': json.dumps(tema.ngrams),
'modification_date': tema.modification_date.isoformat(),
'creation_date': tema.creation_date.isoformat(),
'hidden': 1 if tema.hidden else 0,
}
def cell_to_ngrams(cell: str) -> search_model.NGrams:
return {int(n): ngrams_ for n, ngrams_ in json.loads(cell).items()}
def cell_to_ngrams(cell_str: str) -> search_model.NGrams:
cell: dict[str, list[str]] = json.loads(cell_str)
return {int(n): ngrams_ for n, ngrams_ in cell.items()}
def row_to_tema(row: TemaRowTuple) -> model.Tema:
return model.Tema(
id=row[0],
title=row[1],
properties=IndexedList(map(model.Property.from_dict, json.loads(row[2]))),
links=IndexedList(map(model.Link.from_dict, json.loads(row[3]))),
lyrics=IndexedList(map(model.Lyrics.from_dict, json.loads(row[4]))),
alternatives=json.loads(row[5]),
ngrams=cell_to_ngrams(row[6]),
modification_date=datetime.datetime.fromisoformat(row[7]),
creation_date=datetime.datetime.fromisoformat(row[8]),
hidden=bool(row[9]),
alternatives=json.loads(row[2]),
modification_date=datetime.datetime.fromisoformat(row[3]),
creation_date=datetime.datetime.fromisoformat(row[4]),
hidden=bool(row[5]),
)