commit f918c09a356d54148194228f4b3fb9975e00f9f6 Author: raute Date: Fri Apr 12 16:47:49 2024 +0200 Initial commit. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b47fa8 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# llplenum + +A simple script to convert the minutes of a plenum from Markdown to Dokuwiki (using Pandoc). + +## Usage +Copy the Markdown code to clipboard and call this script. You'll the find the Dokuwiki code in your clipboard, ready to paste. + +## Dependencies +- pandoc +- xclip diff --git a/llplenum b/llplenum new file mode 100755 index 0000000..9f1546c --- /dev/null +++ b/llplenum @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +import datetime +import re +import subprocess +import sys + + +months = ["", + "Januar", "Februar", "März", + "April", "Mai", "Juni", + "Juli", "August", "September", + "Oktober", "November", "Dezember"] + +clipboard = subprocess.check_output(["xclip", "-out", "-selection", "clipboard"]).decode() + +m = re.match( + r"# ([0-9][0-9]+)\. Plenum .+ ([0-9]{1,2})\. (" + "|".join(months[1:]) + ") (20[0-9]{2})", + clipboard) +if not m: + print("Error: Überschrift nicht erkannt.", file=sys.stderr) + sys.exit(1) + +num = int(m.group(1)) +month_name = m.group(3) +year = int(m.group(4)) + +try: + month = months.index(month_name) +except ValueError: + print("Error: Ungültiger Monat.", file=sys.stderr) + sys.exit(2) + +year_earlier = (datetime.date(year, month, 1) - datetime.timedelta(days=31)).year +year_later = (datetime.date(year, month, 1) + datetime.timedelta(days=31)).year + +month_earlier = month - 1 +if month_earlier == 0: + month_earlier = 12 + +month_later = month + 1 +if month_later == 13: + month_later = 1 + +month_name = month_name.lower() +earlier = "verein:plenum:{}_{}_{}".format(str(num - 1).rjust(3, "0"), + months[month_earlier].lower(), + year_earlier) +later = "verein:plenum:{}_{}_{}".format(str(num + 1).rjust(3, "0"), + months[month_later].lower(), + year_later) +links = "[⇐ vorheriges Plenum]({}) | [nächstes Plenum ⇒]({})".format(earlier, + later) + +markdown = "{}\n\n{}".format(links, clipboard) +pandoc_output = subprocess.check_output(["pandoc", "-f", "markdown", "-t", "dokuwiki"], + input=markdown.encode()).decode() +replaced = pandoc_output.replace("[x]", + "").replace("[ ]", + "") +subprocess.run(["xclip", "-in", "-selection", "clipboard"], input=replaced.encode()) +print("Dokuwiki-Code kopiert.")