diff --git a/src/tt/config.py b/src/tt/config.py index 2f3105f..10cfff9 100644 --- a/src/tt/config.py +++ b/src/tt/config.py @@ -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"] diff --git a/src/tt/sync.py b/src/tt/sync.py index 61493c8..03128ba 100644 --- a/src/tt/sync.py +++ b/src/tt/sync.py @@ -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)