sync command
This commit is contained in:
parent
0981bd4d19
commit
98be0fcb2c
@ -59,3 +59,5 @@ def get_column(name):
|
|||||||
# Valid statuses & projects are read dynamically from the user's config.
|
# Valid statuses & projects are read dynamically from the user's config.
|
||||||
STATUSES = get_enum("status")
|
STATUSES = get_enum("status")
|
||||||
PROJECTS = get_enum("projects")
|
PROJECTS = get_enum("projects")
|
||||||
|
SERVER_URL = _load_config()["sync"]["url"]
|
||||||
|
SERVER_KEY = _load_config()["sync"]["key"]
|
||||||
|
@ -1,21 +1,45 @@
|
|||||||
import httpx
|
import httpx
|
||||||
|
from collections import defaultdict
|
||||||
from .controller.things import get_things
|
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):
|
def sync_thing(thing):
|
||||||
resp = httpx.post(
|
resp = httpx.post(
|
||||||
"http://localhost:9999/api/thing/?api_key=j@jpt.sh",
|
SERVER_URL + "thing/",
|
||||||
|
params = {"api_key": SERVER_KEY},
|
||||||
json={
|
json={
|
||||||
"id": thing.id,
|
"id": thing.id,
|
||||||
"data": thing.data,
|
"data": thing.data,
|
||||||
"type": thing.type,
|
"type": thing.type,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
print(resp.text)
|
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
return resp.json()
|
||||||
|
|
||||||
|
|
||||||
def full_sync():
|
def full_sync():
|
||||||
|
sync_view("tasks")
|
||||||
|
actions = defaultdict(int)
|
||||||
# all things for now
|
# all things for now
|
||||||
for thing in get_things(None, None):
|
for thing in get_things(None, None):
|
||||||
sync_thing(thing)
|
action = sync_thing(thing)["action"]
|
||||||
|
actions[action] += 1
|
||||||
|
print(actions)
|
||||||
|
Loading…
Reference in New Issue
Block a user