aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wikijscmd/app.py6
-rw-r--r--wikijscmd/commands.py21
2 files changed, 26 insertions, 1 deletions
diff --git a/wikijscmd/app.py b/wikijscmd/app.py
index 7b2fe0f..9dc3cd5 100644
--- a/wikijscmd/app.py
+++ b/wikijscmd/app.py
@@ -4,7 +4,7 @@ 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
+from wikijscmd.commands import create, edit, single, tree, today, move, fill_in_pages, latest_journal_entry, view
from wikijscmd.tui import tui
def main():
@@ -47,6 +47,10 @@ def main():
parser_tui = subparsers.add_parser("tui", help="lauch a ncurses interface")
parser_tui.set_defaults(command=tui)
+ parser_view = subparsers.add_parser("view", help="open HTML page")
+ parser_view.add_argument("path", type=str, help="the path of the page to view")
+ parser_view.set_defaults(command=view)
+
args = vars(parser.parse_args())
callback = args["command"]
if callback is None:
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)