-- Leo's gemini proxy

-- Connecting to capsule.usebox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini; charset=utf-8; lang=en

Re: My create article script


Posted Sat 15 Apr, 2023.


This is a reply to:


Yretek - My create article script


I found funny that I have my own version of that script. By reducing friction, it is easier to post more frequently, isn't it?


This is mine (in Python):


#!/usr/bin/env python3

from __future__ import annotations
from datetime import date
import os
from os import path
import subprocess
import sys
try:
    from slugify import slugify
except ImportError:
    sys.exit("Please install python3-slugify")

gemlog_dir = "public/gemlog/"


def main():
    if len(sys.argv) != 2:
        sys.exit("usage: %s 'title of the post'" % sys.argv[0])

    title = sys.argv[1]
    created_on = date.today()
    file_name = created_on.strftime("%Y%m%d") + "-" + slugify(title) + ".gmi"
    body = '\n'.join([
        "# " + title,
        created_on.strftime("\nPosted %a %d %b, %Y.\n"),
        "TODO\n",
        "=> ./ Back to the index",
        "=> ../../ Back home\n",
    ])

    if path.isfile(gemlog_dir + file_name):
        sys.exit("{} already exists".format(gemlog_dir + file_name))

    with open(gemlog_dir + file_name, "wt") as fd:
        fd.write(body)

    print("Created {}".format(gemlog_dir + file_name))
    subprocess.call([os.environ.get("EDITOR", "vim"), gemlog_dir + file_name])


if __name__ == "__main__":
    main()

I don't remember the details, I wrote it some time ago -for example, why am I importing annotations if I don't seem to use them?-. Anyway, it works.


Back to the index

Back home

-- Response ended

-- Page fetched on Wed May 8 17:20:45 2024