Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
blallo | fa0023d2d1 | |
blallo | 4d1596c4a2 | |
blallo | 821335d719 | |
blallo | 635780b353 | |
blallo | 51b4e6c112 | |
blallo | 9750623929 | |
blallo | f3ed2b0cc9 |
|
@ -20,6 +20,7 @@ def get_section(obj: T.Dict[T.Text, T.Any], key: T.Text) -> T.Any:
|
||||||
class Config(object):
|
class Config(object):
|
||||||
smtp: T.Dict[T.Text, T.Any] = {}
|
smtp: T.Dict[T.Text, T.Any] = {}
|
||||||
to: T.List[T.Text] = []
|
to: T.List[T.Text] = []
|
||||||
|
cc: T.List[T.Text] = []
|
||||||
store: T.Optional[T.Text] = None
|
store: T.Optional[T.Text] = None
|
||||||
|
|
||||||
def __init__(self, path: T.Text) -> None:
|
def __init__(self, path: T.Text) -> None:
|
||||||
|
@ -35,6 +36,9 @@ class Config(object):
|
||||||
|
|
||||||
self.to = get_section(content, "to")
|
self.to = get_section(content, "to")
|
||||||
|
|
||||||
|
if cc := content.get("cc"):
|
||||||
|
self.cc = cc
|
||||||
|
|
||||||
smtp = get_section(content, "smtp")
|
smtp = get_section(content, "smtp")
|
||||||
for key in [
|
for key in [
|
||||||
"smtp_addr",
|
"smtp_addr",
|
||||||
|
|
|
@ -32,10 +32,10 @@ def main(config: Config):
|
||||||
data.append(get_details(row, aux_data))
|
data.append(get_details(row, aux_data))
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
out.send_no_data(config.to)
|
out.send_no_data(config.to, config.cc)
|
||||||
|
|
||||||
excel = to_excel(data, config.store)
|
excel = to_excel(data, config.store)
|
||||||
out.send_result(config.to, excel)
|
out.send_result(config.to, config.cc, excel)
|
||||||
|
|
||||||
|
|
||||||
def cli():
|
def cli():
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
from datetime import datetime
|
||||||
from email import encoders
|
from email import encoders
|
||||||
from email.mime.base import MIMEBase
|
from email.mime.base import MIMEBase
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
@ -55,13 +56,18 @@ class Notifier(object):
|
||||||
conn.sendmail(self._from, to, email)
|
conn.sendmail(self._from, to, email)
|
||||||
|
|
||||||
@retry_and_log(logger, RETRIES)
|
@retry_and_log(logger, RETRIES)
|
||||||
def send_result(self, to: T.List[T.Text], result: bytes) -> None:
|
def send_result(
|
||||||
|
self, to: T.List[T.Text], cc: T.List[T.Text], result: bytes
|
||||||
|
) -> None:
|
||||||
date = get_date()
|
date = get_date()
|
||||||
body = f"Resoconto dei voli dal sito di AdR per l'aereoporto di Ciampino in data {date}" # noqa: E501
|
body = f"Resoconto dei voli dal sito di AdR per l'aereoporto di Ciampino in data {date}" # noqa: E501
|
||||||
|
|
||||||
message = MIMEMultipart()
|
message = MIMEMultipart()
|
||||||
|
message["Date"] = datetime.now().strftime("%a, %d %b %Y %H:%M:%S %z")
|
||||||
message["From"] = self._from
|
message["From"] = self._from
|
||||||
message["To"] = ",".join(to)
|
message["To"] = ",".join(to)
|
||||||
|
if cc:
|
||||||
|
message["Cc"] = ",".join(cc)
|
||||||
message["Subject"] = f"[{date}] Resoconto CIA da AdR"
|
message["Subject"] = f"[{date}] Resoconto CIA da AdR"
|
||||||
|
|
||||||
message.attach(MIMEText(body, "plain"))
|
message.attach(MIMEText(body, "plain"))
|
||||||
|
@ -78,10 +84,13 @@ class Notifier(object):
|
||||||
|
|
||||||
email = message.as_string()
|
email = message.as_string()
|
||||||
|
|
||||||
self.send(to, email)
|
rcpt = to
|
||||||
|
rcpt.extend(cc)
|
||||||
|
|
||||||
|
self.send(rcpt, email)
|
||||||
|
|
||||||
@retry_and_log(logger, RETRIES)
|
@retry_and_log(logger, RETRIES)
|
||||||
def send_no_data(self, to: T.List[T.Text]) -> None:
|
def send_no_data(self, to: T.List[T.Text], cc: T.List[T.Text]) -> None:
|
||||||
date = get_date()
|
date = get_date()
|
||||||
body = f"""Attenzione
|
body = f"""Attenzione
|
||||||
|
|
||||||
|
@ -91,11 +100,17 @@ il vostro tecnico preferito.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
message = MIMEMultipart()
|
message = MIMEMultipart()
|
||||||
|
message["Date"] = datetime.now().strftime("%a, %d %b %Y %H:%M:%S %z")
|
||||||
message["From"] = self._from
|
message["From"] = self._from
|
||||||
message["To"] = ",".join(to)
|
message["To"] = ",".join(to)
|
||||||
|
if cc:
|
||||||
|
message["Cc"] = ",".join(cc)
|
||||||
message["Subject"] = f"ATTENZIONE: [{date}] Resoconto CIA da AdR"
|
message["Subject"] = f"ATTENZIONE: [{date}] Resoconto CIA da AdR"
|
||||||
|
|
||||||
message.attach(MIMEText(body, "plain"))
|
message.attach(MIMEText(body, "plain"))
|
||||||
email = message.as_string()
|
email = message.as_string()
|
||||||
|
|
||||||
self.send(to, email)
|
rcpt = to
|
||||||
|
rcpt.extend(cc)
|
||||||
|
|
||||||
|
self.send(rcpt, email)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[project]
|
[project]
|
||||||
name = "latecomers"
|
name = "latecomers"
|
||||||
version = "0.3.0"
|
version = "0.3.3"
|
||||||
description = "Retrieve and save data from ADR Ciampino airport"
|
description = "Retrieve and save data from ADR Ciampino airport"
|
||||||
authors = [{name="Leonardo Barcaroli", email="blallo@autistici.org"}]
|
authors = [{name="Leonardo Barcaroli", email="blallo@autistici.org"}]
|
||||||
license = {text="Public Domain"}
|
license = {text="Public Domain"}
|
||||||
|
|
Loading…
Reference in New Issue