aboutsummaryrefslogtreecommitdiff
path: root/wikijscmd
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2022-12-17 20:58:41 -0600
committerMark Powers <mark@marks.kitchen>2022-12-17 20:58:41 -0600
commitadf68faa1438212cb745aa07931ca56891af2933 (patch)
tree7baf1018e304294c66d062ca447b0ebc2cad40e5 /wikijscmd
parent6b8a2bf4328e446c98c08208e15fdaf25f1a9049 (diff)
Add tracker hook
Diffstat (limited to 'wikijscmd')
-rw-r--r--wikijscmd/app.py1
-rw-r--r--wikijscmd/commands.py30
-rw-r--r--wikijscmd/custom_requests.py9
-rw-r--r--wikijscmd/util.py13
4 files changed, 40 insertions, 13 deletions
diff --git a/wikijscmd/app.py b/wikijscmd/app.py
index 9dc3cd5..64ab390 100644
--- a/wikijscmd/app.py
+++ b/wikijscmd/app.py
@@ -3,7 +3,6 @@
import sys
import argparse
-from wikijscmd.config import config
from wikijscmd.commands import create, edit, single, tree, today, move, fill_in_pages, latest_journal_entry, view
from wikijscmd.tui import tui
diff --git a/wikijscmd/commands.py b/wikijscmd/commands.py
index ae90507..5a10099 100644
--- a/wikijscmd/commands.py
+++ b/wikijscmd/commands.py
@@ -3,25 +3,33 @@ import subprocess
import time
import os
-from wikijscmd import graphql_queries
from datetime import datetime, timedelta
+
+from wikijscmd import graphql_queries
+from wikijscmd.config import config
from wikijscmd.util import clean_filename, get_tree, open_editor, get_single_page, print_item, args_for_date
-def create(path, title, content=None):
+def create(path, title, content=None, edit=False):
page = get_single_page(path)
if page is not None:
print("Page already exists with path: %s" % path)
if input("Edit it? (y/n) ") == "y":
edit(path)
return
- if not content:
- content = open_editor("create", path, "")
- response = graphql_queries.create_page(content, title, path)
- result = response["data"]["pages"]["create"]["responseResult"]
- if not result["succeeded"]:
- print("Error!", result["message"])
- sys.exit(1)
- print(result["message"])
+ if content is None:
+ content = ""
+ # Edit if requested or no content was supplied
+ if edit or not content:
+ content = open_editor("create", path, content)
+ if content:
+ response = graphql_queries.create_page(content, title, path)
+ result = response["data"]["pages"]["create"]["responseResult"]
+ if not result["succeeded"]:
+ print("Error!", result["message"])
+ sys.exit(1)
+ print(result["message"])
+ else:
+ print("No content")
def tree(regex):
"""
@@ -109,7 +117,7 @@ def fill_in_pages():
pending_date = last_date.date()
while pending_date < today:
pending_date += timedelta(days=1)
- create(**args_for_date(pending_date))
+ create(**args_for_date(pending_date), edit=True)
def today():
"""
diff --git a/wikijscmd/custom_requests.py b/wikijscmd/custom_requests.py
index bc9b16e..a32a14c 100644
--- a/wikijscmd/custom_requests.py
+++ b/wikijscmd/custom_requests.py
@@ -28,3 +28,12 @@ def send_query(query, query_vars):
handle_errors(r)
return r.json()
+def query_date(date):
+ res = requests.get(
+ f'{config["tracker"]["url"]}/{date}',
+ auth=requests.auth.HTTPBasicAuth(
+ config["tracker"]["username"], config["tracker"]["password"])
+ )
+ if res.status_code != 200:
+ return []
+ return res.json()
diff --git a/wikijscmd/util.py b/wikijscmd/util.py
index 6720831..e16bf85 100644
--- a/wikijscmd/util.py
+++ b/wikijscmd/util.py
@@ -1,4 +1,5 @@
from wikijscmd import graphql_queries
+from wikijscmd import custom_requests
import subprocess
import re
import os
@@ -57,7 +58,17 @@ def open_editor(action, pathname, initial_body):
return new_body
def args_for_date(date):
- return {
+ obj = {
"path": date.strftime("journal/%Y/%b/%d").lower(),
"title": date.strftime("%B %-d"),
}
+ date_content_json = custom_requests.query_date(date.strftime("%Y-%m-%d"))
+ if date_content_json:
+ date_content = ""
+ for item in date_content_json:
+ if item.get("key"):
+ date_content += f'{item["datatype"]}: {item["key"]}-{item["value"]}\n'
+ else:
+ date_content += f'{item["datatype"]}: {item["value"]}\n'
+ obj["content"] = str(date_content)
+ return obj