diff --git a/read_db.sh b/read_db.sh index 5a20c67..f25a4b6 100755 --- a/read_db.sh +++ b/read_db.sh @@ -2,12 +2,13 @@ read -s -p "DB-Passwort: " password; echo -raw_proto=$(echo $password | ssh fsmi "psql -A -t -h fsmi-db fsmi -c \"select datum from protokolle where ist_veroeffentlicht='f' and name is null\"" 2> /dev/null) +raw_proto=$(echo $password | ssh fsmi "psql -A -t -h fsmi-db fsmi -c \"select datum from protokolle where ist_veroeffentlicht='f' and name is null order by datum asc\"" 2> /dev/null) echo $password | ssh fsmi "psql -A -t -h fsmi-db fsmi -c \"select protokoll from protokolle where ist_veroeffentlicht='f' and name is null order by datum desc limit 1\"" 2> /dev/null > data/last_proto for proto in $raw_proto; do echo "* FSR-Protokoll vom $proto" + echo "$proto" > data/last_date done > data/uvproto.txt grep -oP '(?<=nächste Redeleitung: ).*(?=)' data/last_proto > data/redeleitung diff --git a/read_topmails.py b/read_topmails.py new file mode 100755 index 0000000..4290cb3 --- /dev/null +++ b/read_topmails.py @@ -0,0 +1,50 @@ +#!/usr/bin/python3 +import mailbox +import jinja2 +import email.header +import email.utils +import yaml +import datetime +import sys, os +import pypandoc +import argparse +import quopri +import pytz +from pprint import pprint +from dateutil import parser + +MAILDIR = "/home/yannik/mail/INBOX.Mailinglisten.FSMI/" +CONFIG_FILE = "generator.conf" + +def decode_header(header): + decoded_header = email.header.decode_header(header)[0] + encoding = decoded_header[1] or "ascii" + if encoding == "unknown-8bit": + encoding = "ascii" + return decoded_header[0].decode(encoding, errors="replace") if isinstance(decoded_header[0], bytes) else decoded_header[0] + +if __name__ == "__main__": + config = yaml.full_load(open(CONFIG_FILE)) + in_mbox = mailbox.Maildir(MAILDIR) + out_mbox = mailbox.mbox(config["top_mbox_file"]) + + out_mbox.clear() + + buffer = [] + + timezone = pytz.timezone("Europe/Berlin") + last_fsr_date = datetime.date.fromisoformat(open("data/last_date").read().strip()) + last_fsr_datetime = datetime.datetime.combine(last_fsr_date, datetime.time(17, 30), timezone) + + for message in in_mbox: + if message["List-Id"]: + if "top.fsmi.uni-karlsruhe.de" in decode_header(message["List-Id"]).strip(): + date = parser.parse(message["Date"]) + if date > last_fsr_datetime: + buffer.append(message) + + for message in sorted(buffer, key=lambda x: parser.parse(x["Date"])): + out_mbox.add(message) + + out_mbox.close() +