💾 Archived View for capsule.usebox.net › gemlog › 20230415-re-my-create-article-script.gmi captured on 2023-05-24 at 17:42:16. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-04-19)

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

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