sync prototype
This commit is contained in:
parent
5ca4a54ffb
commit
0981bd4d19
@ -3,7 +3,8 @@ import httpx
|
||||
import lxml.html
|
||||
import sqlite3
|
||||
from typing_extensions import Annotated
|
||||
from .db import initialize_db
|
||||
from .db import initialize_db, db
|
||||
from .sync import full_sync
|
||||
from .tui.things import run as things_tui
|
||||
|
||||
# from .tui.overview import run as overview_tui
|
||||
@ -68,8 +69,6 @@ def backup(backup_path: str):
|
||||
"""
|
||||
Perform a SQLite backup using the .backup dot command
|
||||
"""
|
||||
from tt.db import db
|
||||
|
||||
conn = db.connection()
|
||||
|
||||
backup_conn = None
|
||||
@ -81,5 +80,14 @@ def backup(backup_path: str):
|
||||
backup_conn.close()
|
||||
|
||||
|
||||
@app.command()
|
||||
def sync():
|
||||
"""
|
||||
Sync with tt server.
|
||||
"""
|
||||
initialize_db()
|
||||
full_sync()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
|
@ -80,6 +80,8 @@ def get_things(
|
||||
# TODO: which fields are searchable should by dynamic
|
||||
query = query.where(fn.Lower(Thing.data["text"]).contains(search_text.lower()))
|
||||
|
||||
if filters is None:
|
||||
filters = {}
|
||||
for param, val in filters.items():
|
||||
if val is not None:
|
||||
# no _in query for JSON fields, so use OR
|
||||
|
21
src/tt/sync.py
Normal file
21
src/tt/sync.py
Normal file
@ -0,0 +1,21 @@
|
||||
import httpx
|
||||
from .controller.things import get_things
|
||||
|
||||
|
||||
def sync_thing(thing):
|
||||
resp = httpx.post(
|
||||
"http://localhost:9999/api/thing/?api_key=j@jpt.sh",
|
||||
json={
|
||||
"id": thing.id,
|
||||
"data": thing.data,
|
||||
"type": thing.type,
|
||||
}
|
||||
)
|
||||
print(resp.text)
|
||||
resp.raise_for_status()
|
||||
|
||||
|
||||
def full_sync():
|
||||
# all things for now
|
||||
for thing in get_things(None, None):
|
||||
sync_thing(thing)
|
Loading…
Reference in New Issue
Block a user