[project] extract tui code into own module, also extraxt (db) models into their own module
Some checks failed
ci/woodpecker/push/workflow Pipeline failed
Some checks failed
ci/woodpecker/push/workflow Pipeline failed
This commit is contained in:
parent
d58ae7aad1
commit
173d23addf
3 changed files with 155 additions and 95 deletions
|
|
@ -1,23 +1,57 @@
|
|||
import logging
|
||||
import re
|
||||
import uuid
|
||||
|
||||
from natsort import natsorted
|
||||
from sqlmodel import (
|
||||
Field,
|
||||
SQLModel,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class TeilchenInput(SQLModel):
|
||||
|
||||
class TeilchenBase(SQLModel):
|
||||
text: str
|
||||
|
||||
|
||||
class Teilchen(TeilchenInput, table=True):
|
||||
class TeilchenCreate(TeilchenBase):
|
||||
description: str | None
|
||||
name: str = Field(index=True)
|
||||
number: int = Field(default=1)
|
||||
tags: str | None
|
||||
|
||||
text: str # The original input as entered by the user
|
||||
|
||||
|
||||
class Teilchen(TeilchenCreate, table=True):
|
||||
id: uuid.UUID = Field(default_factory=uuid.uuid7, primary_key=True)
|
||||
|
||||
name: str = Field(index=True)
|
||||
description: str | None
|
||||
tags: str | None
|
||||
number: int = Field(default=1)
|
||||
|
||||
def make_teilchen_input(text: str) -> TeilchenCreate | None:
|
||||
if not text:
|
||||
logger.error("Empty text.")
|
||||
return None
|
||||
|
||||
name_end = text.find(".")
|
||||
name = text[0:name_end]
|
||||
if not name:
|
||||
logger.error("Could not extract name.")
|
||||
return None
|
||||
|
||||
description_start = text.find('"', name_end + 1)
|
||||
description_end = text.find('"', description_start + 1)
|
||||
description = text[description_start:description_end]
|
||||
if not description:
|
||||
logger.warning("Could not extract description.")
|
||||
|
||||
tags = re.findall(r"#\w+", text.lower())
|
||||
if not tags:
|
||||
logger.warning("No tags found in text")
|
||||
|
||||
return TeilchenCreate(
|
||||
name=name,
|
||||
description=description,
|
||||
tags=" ".join(natsorted(tags)),
|
||||
text=text,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue