Skip to content

Instantly share code, notes, and snippets.

@MonadMonAmi
Created November 29, 2021 12:00
Show Gist options
  • Save MonadMonAmi/03dbc5deb4c070b15f98a0d5bb649147 to your computer and use it in GitHub Desktop.
Save MonadMonAmi/03dbc5deb4c070b15f98a0d5bb649147 to your computer and use it in GitHub Desktop.
My Script for editing Zim Diary in simple text editor
import argparse
import subprocess
from datetime import date, timedelta
from os import path
from shutil import os
from time import sleep
import sys
import re
import zim_datetimetz as tz
NOTES_PATH = "/home/ray/Notebooks/Notes"
PREFIX = "Journal/"
TEMPLATE = f"""Content-Type: text/x-zim-wiki
Wiki-Format: zim 0.6
Creation-Date: {tz.now().isoformat()}
====== {date.today().day} ======
{date.today().strftime('%A %d. %B %Y')}
"""
if __name__ == "__main__":
argv = sys.argv
is_default_date = True
if len(argv) > 1:
match = re.match('[\d]+$', argv[1])
if match:
is_default_date = False
dest_date = date.today() - timedelta(days=int(argv[1]))
note_path = PREFIX + dest_date.strftime("%Y/%m/%d")
else:
note_path = sys.argv[1].replace(':', '/')
else:
note_path = PREFIX + date.today().strftime("%Y/%m/%d")
abs_path = NOTES_PATH + '/' + note_path + '.txt'
if len(argv) == 1:
dirs_path, _, _ = abs_path.rpartition('/')
os.makedirs(dirs_path, exist_ok=True)
print(abs_path)
if not path.exists(abs_path) and is_default_date:
with open(abs_path, 'w') as f:
f.write(TEMPLATE)
if path.exists(abs_path):
# proc = subprocess.Popen(["mousepad", "-o", "window", abs_path])
proc = subprocess.Popen(["geany", "-t", abs_path])
print("pid= ", proc.pid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment