allow package specific actions
This commit is contained in:
49
fsmi_fsr/actions.py
Normal file
49
fsmi_fsr/actions.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import subprocess
|
||||
import os
|
||||
import mailbox
|
||||
import datetime
|
||||
|
||||
import pytz
|
||||
from dateutil import parser as dateutilparser
|
||||
|
||||
def clean_data():
|
||||
open(config["top_mbox_file"], 'w').close()
|
||||
|
||||
|
||||
for top in config["pre_tops"]:
|
||||
if "file" in top and os.path.isfile(top["file"]):
|
||||
os.remove(top["file"])
|
||||
|
||||
for top in config["post_tops"]:
|
||||
if "file" in top and os.path.isfile(top["file"]):
|
||||
os.remove(top["file"])
|
||||
|
||||
def read_db():
|
||||
subprocess.run(["helpers/read_db.sh"], check=True)
|
||||
|
||||
def read_topmails():
|
||||
in_mbox = mailbox.Maildir(config["top_inbox_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(config["last_date_file"]).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 config["top_list_id"] in generate.decode_header(message["List-Id"]).strip():
|
||||
date = dateutilparser.parse(message["Date"])
|
||||
if date > last_fsr_datetime:
|
||||
buffer.append(message)
|
||||
|
||||
for message in sorted(buffer, key=lambda x: dateutilparser.parse(x["Date"])):
|
||||
out_mbox.add(message)
|
||||
|
||||
out_mbox.close()
|
||||
|
||||
def compile_presentation():
|
||||
subprocess.run(["helpers/compile_presentation.sh"], check=True)
|
||||
Reference in New Issue
Block a user