add script to extract top mails
This commit is contained in:
@@ -2,12 +2,13 @@
|
|||||||
read -s -p "DB-Passwort: " password;
|
read -s -p "DB-Passwort: " password;
|
||||||
echo
|
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
|
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;
|
for proto in $raw_proto;
|
||||||
do
|
do
|
||||||
echo "* FSR-Protokoll vom $proto"
|
echo "* FSR-Protokoll vom $proto"
|
||||||
|
echo "$proto" > data/last_date
|
||||||
done > data/uvproto.txt
|
done > data/uvproto.txt
|
||||||
|
|
||||||
grep -oP '(?<=nächste Redeleitung: ).*(?=</li>)' data/last_proto > data/redeleitung
|
grep -oP '(?<=nächste Redeleitung: ).*(?=</li>)' data/last_proto > data/redeleitung
|
||||||
|
|||||||
50
read_topmails.py
Executable file
50
read_topmails.py
Executable file
@@ -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()
|
||||||
|
|
||||||
Reference in New Issue
Block a user