clean up; remove old files

This commit is contained in:
jpt 2025-05-04 19:06:12 -05:00
parent 72588fd9c6
commit 4f408d7ceb
5 changed files with 7 additions and 128 deletions

View file

@ -6,9 +6,6 @@ from typing_extensions import Annotated
from .db import initialize_db, db from .db import initialize_db, db
from .sync import full_sync from .sync import full_sync
from .tui.things import run as things_tui from .tui.things import run as things_tui
# from .tui.overview import run as overview_tui
from .tui.recurring import run as recurring_tui
from .controller.things import add_thing from .controller.things import add_thing
app = typer.Typer() app = typer.Typer()
@ -52,18 +49,6 @@ def table(
things_tui(view) things_tui(view)
@app.command()
def generators():
initialize_db()
recurring_tui()
@app.command()
def overview():
initialize_db()
overview_tui()
@app.command() @app.command()
def backup(backup_path: str): def backup(backup_path: str):
""" """

View file

@ -1,66 +0,0 @@
import json
from datetime import date, timedelta
from ..db import db, ThingGenerator
from .things import add_thing
def get_generator(item_id: int) -> ThingGenerator:
return ThingGenerator.get_by_id(item_id)
def get_generators() -> list[ThingGenerator]:
query = ThingGenerator.select().where(~ThingGenerator.deleted)
return query.order_by("type", "template")
def add_generator(
template: str,
type: str,
val: str,
) -> ThingGenerator:
# JSON for future expansion
config = json.dumps({"val": val})
with db.atomic():
thing = ThingGenerator.create(
template=template,
type=type,
config=config,
)
return thing
def generate_needed_things():
to_create = []
for g in get_generators():
next = g.next_at()
if not next:
continue
# TODO: make configurable
if date.today() - next > timedelta(days=14):
to_create.append(
{
"text": g.template.format(next=next),
"project": "recurring",
"due": next,
}
)
for c in to_create:
add_thing(**c)
return to_create
def update_generator(
item_id: int,
**kwargs,
) -> ThingGenerator:
# replace "val" with JSON
if "val" in kwargs:
config = {"val": kwargs.pop("val")}
kwargs["config"] = json.dumps(config)
with db.atomic():
query = ThingGenerator.update(kwargs).where(ThingGenerator.id == item_id)
query.execute()
thing = ThingGenerator.get_by_id(item_id)
return thing

View file

@ -10,9 +10,9 @@ def sync_view(view_name):
filters = view["filters"] filters = view["filters"]
resp = httpx.post( resp = httpx.post(
SERVER_URL + "view/", SERVER_URL + "view/",
params = {"api_key": SERVER_KEY}, params={"api_key": SERVER_KEY},
json={ json={
"name": view['name'], "name": view["name"],
"columns": columns, "columns": columns,
"filters": filters, "filters": filters,
"sort": view["sort"], "sort": view["sort"],
@ -24,7 +24,7 @@ def sync_view(view_name):
def sync_thing(thing): def sync_thing(thing):
resp = httpx.post( resp = httpx.post(
SERVER_URL + "thing/", SERVER_URL + "thing/",
params = {"api_key": SERVER_KEY}, params={"api_key": SERVER_KEY},
json={ json={
"id": thing.id, "id": thing.id,
"data": thing.data, "data": thing.data,

View file

@ -1,6 +1,6 @@
from textual.app import App, ComposeResult from textual.app import App, ComposeResult
from textual.containers import ScrollableContainer, Horizontal from textual.containers import ScrollableContainer, Horizontal
from textual.widgets import DataTable, Static, Label from textual.widgets import DataTable, Label
from textual.binding import Binding from textual.binding import Binding
from datetime import datetime from datetime import datetime
@ -98,11 +98,11 @@ class Overview(App):
margin: 1 1; margin: 1 1;
} }
Label { Label {
align: center middle; align: center middle;
background: purple; background: purple;
} }
#lists { #lists {
height: 60%; height: 60%;
} }

View file

@ -1,40 +0,0 @@
import json
from ..controller.generators import (
get_generator,
get_generators,
add_generator,
update_generator,
generate_needed_things,
)
from .editor import (
TableEditor,
)
class GenEditor(TableEditor):
def __init__(self):
super().__init__()
self.update_item_callback = update_generator
self.add_item_callback = add_generator
self.get_item_callback = get_generator
self.table_config = self._load_config("recurring")
def refresh_items(self):
generated = generate_needed_things()
if num := len(generated):
self.notify(f"created {num} things")
items = get_generators()
for item in items:
self.table.add_row(
str(item.id),
item.template,
item.type,
json.loads(item.config)["val"],
str(item.next_at()),
)
def run():
app = GenEditor()
app.run()