aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2020-12-28 21:53:47 -0600
committerMark Powers <mark@marks.kitchen>2020-12-28 21:53:47 -0600
commita160d7d9f082a65a7a2b4ffc0e6fe86174ebfac4 (patch)
tree667c2cb1993b68a8b519af7148b04ee49f2ed38e
parent5745b14719e7c16c12d85b60adafd6ea0335731e (diff)
Add move command
-rw-r--r--README.md3
-rw-r--r--graphql_queries.py20
-rwxr-xr-xmain.py23
3 files changed, 44 insertions, 2 deletions
diff --git a/README.md b/README.md
index 990355a..fbd8927 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,9 @@ Creates a page with the path `YYYY/MM/DD` and title as the date name. For
example, if the date is January 1, 1970, this is equivalent of running the
command `create 1970/01/01 "Janurary 1"`.
+### move (PATH|ID) DEST\_PATH
+Moves a page identified by the path or ID given to the destination path.
+
## Installation
Clone the repository or download the source code.
diff --git a/graphql_queries.py b/graphql_queries.py
index 6d7094f..db23f23 100644
--- a/graphql_queries.py
+++ b/graphql_queries.py
@@ -19,3 +19,23 @@ def edit_page(page_id, content, title, path):
query = 'mutation ($id: Int!, $content: String!, $path: String!, $title: String!){\npages {\nupdate(\nid: $id\ncontent: $content\ndescription: ""\neditor: "markdown"\nisPrivate: false\nisPublished: true\nlocale: "en"\npath: $path\npublishEndDate: ""\npublishStartDate: ""\nscriptCss: ""\nscriptJs: ""\ntags: []\ntitle: $title\n) {\nresponseResult {\nsucceeded\nerrorCode\nslug\nmessage\n__typename\n}\npage {\nid\nupdatedAt\n__typename\n}\n__typename\n}\n__typename\n}\n}'
query_vars = {"id": page_id, "content": content, "title": title, "path": path}
return custom_requests.send_query(query, query_vars)
+
+def move_page(page_id, destination_path):
+ query = '''mutation ($id: Int!, $destinationPath: String!, $destinationLocale: String!) {
+ pages {
+ move(id: $id, destinationPath: $destinationPath, destinationLocale: $destinationLocale) {
+ responseResult {
+ succeeded
+ errorCode
+ slug
+ message
+ __typename
+ }
+ __typename
+ }
+ __typename
+ }
+ }'''
+ query_vars = {"id": page_id, "destinationPath": destination_path, "destinationLocale": "en"}
+ return custom_requests.send_query(query, query_vars)
+
diff --git a/main.py b/main.py
index 9a0a51e..f792d05 100755
--- a/main.py
+++ b/main.py
@@ -73,7 +73,7 @@ def get_single_page(argv):
def single(argv):
if len(argv) != 1:
print("Usage: ./main.py single <id|path>")
- sys.exit(0)
+ sys.exit(1)
page = get_single_page(argv)
if page is None:
print("No page with path: %s" % argument)
@@ -82,6 +82,23 @@ def single(argv):
print("-" * 80)
print(page["content"])
+def move(argv):
+ if len(argv) != 2:
+ print("Usage: ./main.py move <src> <dest>")
+ sys.exit(1)
+ source = argv[0]
+ dest = argv[1]
+ 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 clean_filename(pathname):
pathname = str(pathname).strip().replace('/', '_')
pathname = re.sub(r'\W', '', pathname)
@@ -141,13 +158,15 @@ def main():
print("\tsingle <id|path>")
print("\tedit <id|path>")
print("\ttoday")
+ print("\tmove <source_path|id> <dest_path>")
sys.exit(0)
commands = {
"create": create,
"tree": tree,
"single": single,
"edit": edit,
- "today": today
+ "today": today,
+ "move": move
}
command = sys.argv[1]
if command in commands: