sync command

This commit is contained in:
jpt 2025-05-03 22:36:34 -05:00
parent 0981bd4d19
commit 98be0fcb2c
2 changed files with 33 additions and 7 deletions

View File

@ -59,3 +59,5 @@ def get_column(name):
# Valid statuses & projects are read dynamically from the user's config.
STATUSES = get_enum("status")
PROJECTS = get_enum("projects")
SERVER_URL = _load_config()["sync"]["url"]
SERVER_KEY = _load_config()["sync"]["key"]

View File

@ -1,21 +1,45 @@
import httpx
from collections import defaultdict
from .controller.things import get_things
from .config import get_view, get_column, SERVER_KEY, SERVER_URL
def sync_view(view_name):
view = get_view(view_name)
columns = {c: get_column(c) for c in view["columns"]}
filters = view["filters"]
resp = httpx.post(
SERVER_URL + "view/",
params = {"api_key": SERVER_KEY},
json={
"name": view['name'],
"columns": columns,
"filters": filters,
"sort": view["sort"],
},
)
resp.raise_for_status()
def sync_thing(thing):
resp = httpx.post(
"http://localhost:9999/api/thing/?api_key=j@jpt.sh",
SERVER_URL + "thing/",
params = {"api_key": SERVER_KEY},
json={
"id": thing.id,
"data": thing.data,
"type": thing.type,
}
"id": thing.id,
"data": thing.data,
"type": thing.type,
},
)
print(resp.text)
resp.raise_for_status()
return resp.json()
def full_sync():
sync_view("tasks")
actions = defaultdict(int)
# all things for now
for thing in get_things(None, None):
sync_thing(thing)
action = sync_thing(thing)["action"]
actions[action] += 1
print(actions)