💾 Archived View for hackersphere.space › ~willowf › gemlog › journal.py captured on 2023-03-20 at 17:50:12.

View Raw

More Information

➡️ Next capture (2023-09-28)

-=-=-=-=-=-=-

#!/usr/bin/env python3
import os
import sys
import subprocess
from datetime import date, datetime, timedelta


today = date.today().strftime("%Y-%m-%d")
yesterday = (datetime.now() - timedelta(1)).strftime("%Y-%m-%d")
tomorrow  = (datetime.now() + timedelta(1)).strftime("%Y-%m-%d")
today_human_readable = date.today().strftime("%B %d, %Y")

pwd_var = "@@" + "PWD" + "@@"
jhd_var = "@@" + "JOURNAL-HEADER" + "@@"

filename = today + ".gmi"
label = today_human_readable
if len(sys.argv) > 1:
  label = " ".join(sys.argv[1:])

index_line = f"=> {pwd_var}/{filename} {label}"
post_links = f"""
=> {pwd_var}/{yesterday}.gmi Previous post
=> {pwd_var}/{tomorrow}.gmi Next post
"""

if not os.path.exists(filename):
  with open(filename, "w+") as file:
    file.write(f"{jhd_var}{post_links}")
  with open("index.gmi", "a") as index_file:
    index_file.write(index_line)

subprocess.run(f"nano -q -a -M -S -ET2 -l -L --guidestripe=100 {filename}", shell=True)