aboutsummaryrefslogtreecommitdiff
path: root/commands.py
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2021-09-27 22:02:49 -0500
committerMark Powers <mark@marks.kitchen>2021-09-27 22:02:49 -0500
commit4e4b0997a2172e00c8a46acb6889fe2c8c939a09 (patch)
tree8ccc07bff1ae7f98a34d6f18d47b3595ebc4712b /commands.py
parent4493e31a1afaf49187fc9a151982279d83b71f65 (diff)
Add packaging tooling
Diffstat (limited to 'commands.py')
-rw-r--r--commands.py113
1 files changed, 0 insertions, 113 deletions
diff --git a/commands.py b/commands.py
deleted file mode 100644
index 4d941cf..0000000
--- a/commands.py
+++ /dev/null
@@ -1,113 +0,0 @@
-import sys
-
-import graphql_queries
-from datetime import datetime, timedelta
-from util import clean_filename, get_tree, open_editor, get_single_page, print_item, args_for_date
-
-def create(path, title, content=None):
- 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"])
-
-def tree(regex):
- """
- Finds pages based on a path search
- """
- for item in get_tree(regex):
- print_item(item)
-
-def single(path, raw=False):
- """
- View a page with the given path
- """
- page = get_single_page(path)
- if page is None:
- print("No page with path: %s" % path)
- sys.exit(1)
- if raw:
- print("-" * 80)
- print_item(page)
- print("-" * 80)
- print(page["content"])
-
-def move(source, dest):
- """
- Move a page from one path to another
- """
- page = get_single_page(source)
- if page is None:
- print("Source page %s does not exist" % source)
- sys.exit(1)
- response = graphql_queries.move_page(page["id"], dest)
- result = response["data"]["pages"]["move"]["responseResult"]
- if not result["succeeded"]:
- print("Error!", result["message"])
- sys.exit(1)
- print(result["message"])
-
-def edit(path, save=False):
- """
- Edit a page
- """
- page = get_single_page(path)
- if page is None:
- print("No page with path: %s" % path)
- if input("Create it? (y/n) ") == "y":
- title = input("Enter the title: ").strip()
- create(path, title)
- return
- body = page["content"]
-
- # Open it in editor
- new_body = open_editor("edit", path, body)
-
- # Prompt user to save it to the wiki
- print_item(page)
- print("-" * 80)
- print(new_body)
- print("-" * 80)
- if save or input("Save changes? (y/n) ") == "y":
- response = graphql_queries.edit_page(page["id"], new_body, page["title"], page["path"])
- result = response["data"]["pages"]["update"]["responseResult"]
- if not result["succeeded"]:
- print("Error!", result["message"])
- sys.exit(1)
- print(result["message"])
-
-def fill_in_pages():
- last_date = None
- for page in get_tree("journal"):
- try:
- date = datetime.strptime(page["path"], "journal/%Y/%b/%d")
- if last_date is None or date > last_date:
- last_date = date
- except ValueError:
- continue
- today = datetime.now().date()
- if last_date is None:
- last_date = today
- pending_date = last_date.date()
- while pending_date < today:
- pending_date += timedelta(days=1)
- create(**args_for_date(pending_date))
-
-def today():
- """
- Creates a journal page with the path "journal/YYYY/MM/DD"
- """
- args = args_for_date(datetime.now().date())
- if get_single_page(args["path"]) is not None:
- edit(args["path"])
- else:
- create(**args)