diff options
author | Mark Powers <mark@marks.kitchen> | 2022-02-20 20:41:34 -0600 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2022-02-20 20:41:34 -0600 |
commit | a8d4877907f9df3d0ba88f900440e4cb4d7603b1 (patch) | |
tree | 10ff70059e1a79970c3f030b93e5909bce76e436 /wikijscmd/commands.py | |
parent | 5ad896564bb220137b500be4549bd5b714a08069 (diff) |
Add view command
Diffstat (limited to 'wikijscmd/commands.py')
-rw-r--r-- | wikijscmd/commands.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/wikijscmd/commands.py b/wikijscmd/commands.py index 84f8916..ae90507 100644 --- a/wikijscmd/commands.py +++ b/wikijscmd/commands.py @@ -1,4 +1,7 @@ import sys +import subprocess +import time +import os from wikijscmd import graphql_queries from datetime import datetime, timedelta @@ -117,3 +120,21 @@ def today(): edit(args["path"]) else: create(**args) + +def view(path): + """ + Opens a journal page in the defaul program + """ + page = get_single_page(path) + if page is None: + print("No page with path: %s" % path) + sys.exit(1) + filename = "/tmp/wikijscmd-"+clean_filename(path)+".md" + out_filename = "/tmp/wikijscmd-"+clean_filename(path)+".html" + with open(filename, "w") as f: + f.write(page["content"]) + subprocess.run(["pandoc", filename, "-o", out_filename]) + subprocess.run(["xdg-open", out_filename]) + time.sleep(5) + os.remove(filename) + os.remove(out_filename) |