43 lines
1.1 KiB
Python
Executable File
43 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf8 -*-
|
|
|
|
import MosDb
|
|
import MosReport
|
|
import datetime
|
|
from email.message import EmailMessage
|
|
from email.mime.text import MIMEText
|
|
from email.headerregistry import Address
|
|
from email.utils import formatdate
|
|
from subprocess import Popen, PIPE
|
|
|
|
db = MosDb.MosDb()
|
|
|
|
items = db.get_daily_oa()
|
|
#items = db.get_daily_oa("-1 day")
|
|
db.finish()
|
|
|
|
(output_text, output_csv) = MosReport.get_report(items)
|
|
|
|
msg = EmailMessage()
|
|
msg["Date"] = formatdate(localtime=True)
|
|
msg["Subject"] = "Lautheitsbericht {:%Y-%m-%d}".format(datetime.datetime.now())
|
|
msg["From"] = Address("Lautheitsüberwachung", "broadcast-support", "weltn24.de")
|
|
msg["To"] = (
|
|
Address("serb", "sebastian.erb", "weltn24.de"),
|
|
Address("mbirth", "markus.birth", "weltn24.de")
|
|
)
|
|
|
|
msg.set_content(output_text)
|
|
msg.make_mixed()
|
|
|
|
att = MIMEText(output_csv, _subtype="csv", _charset="utf-8")
|
|
att.add_header("Content-Disposition", "attachment", filename="lautheit.csv")
|
|
|
|
msg.attach(att)
|
|
|
|
#print(repr(clips))
|
|
print(msg.as_string())
|
|
p = Popen(["/usr/sbin/sendmail", "-oi", "markus.birth@weltn24.de", "sebastian.erb@weltn24.de"], stdin=PIPE)
|
|
p.communicate(msg.as_bytes())
|
|
|