Initial commit.
This commit is contained in:
commit
f918c09a35
|
@ -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
|
|
@ -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]",
|
||||
"<fs x-large>☑</fs>").replace("[ ]",
|
||||
"<fs x-large>☐</fs>")
|
||||
subprocess.run(["xclip", "-in", "-selection", "clipboard"], input=replaced.encode())
|
||||
print("Dokuwiki-Code kopiert.")
|
Loading…
Reference in New Issue