From adf68faa1438212cb745aa07931ca56891af2933 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sat, 17 Dec 2022 20:58:41 -0600 Subject: Add tracker hook --- wikijscmd/commands.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'wikijscmd/commands.py') 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(): """ -- cgit v1.2.3