Add support for MacOS.
This commit is contained in:
parent
4b7346047d
commit
fb52015445
|
@ -6,4 +6,5 @@ A simple script to format the minutes of a plenum (Markdown) for the LeineLab wi
|
|||
Copy the Markdown code to clipboard and call this script. You'll the find the modified code in your clipboard, ready to paste.
|
||||
|
||||
## Dependencies
|
||||
- xclip
|
||||
- xclip (Linux)
|
||||
- pbcopy/pbpaste (MacOS)
|
||||
|
|
29
llplenum
29
llplenum
|
@ -1,20 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import datetime
|
||||
import platform
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def get_clipboard():
|
||||
if platform.system() == "Darwin":
|
||||
return subprocess.check_output(["pbpaste"]).decode()
|
||||
|
||||
return subprocess.check_output(["xclip", "-out", "-selection", "clipboard"]).decode()
|
||||
|
||||
|
||||
def set_clipboard(content):
|
||||
if platform.system() == "Darwin":
|
||||
subprocess.run(["pbcopy"], input=content.encode())
|
||||
return
|
||||
|
||||
subprocess.run(["xclip", "-in", "-selection", "clipboard"], input=content.encode())
|
||||
|
||||
|
||||
# main
|
||||
if platform.system() not in ["Darwin", "Linux"]:
|
||||
print("Nicht unterstütztes Betriebssystem.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
months = ["",
|
||||
"Januar", "Februar", "März",
|
||||
"April", "Mai", "Juni",
|
||||
"Juli", "August", "September",
|
||||
"Oktober", "November", "Dezember"]
|
||||
|
||||
clipboard = subprocess.check_output(["xclip", "-out", "-selection", "clipboard"]).decode()
|
||||
clipboard = get_clipboard()
|
||||
|
||||
m = re.match(r"# ([0-9][0-9]+)\. Plenum .+ ([0-9]{1,2})\. (" + "|".join(months[1:]) + ") (20[0-9]{2})",
|
||||
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)
|
||||
|
@ -52,5 +75,5 @@ links = "[⇐ vorheriges Plenum]({}) | [nächstes Plenum ⇒]({})".format(earlie
|
|||
markdown = "{}\n\n{}".format(links, clipboard)
|
||||
output = f"<!DOCTYPE markdown>\n\n{markdown}"
|
||||
replaced = output.replace("[x]", "<fs x-large>☑</fs>").replace("[ ]", "<fs x-large>☐</fs>")
|
||||
subprocess.run(["xclip", "-in", "-selection", "clipboard"], input=replaced.encode())
|
||||
set_clipboard(replaced)
|
||||
print("Dokuwiki-Code kopiert.")
|
||||
|
|
Loading…
Reference in New Issue