Cleanup
This commit is contained in:
parent
3973986011
commit
0d73059281
@ -6,16 +6,16 @@ import pandas as pd
|
|||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
|
|
||||||
|
|
||||||
def read_data(
|
def construct_mails(
|
||||||
data_file: str,
|
data_file: Path,
|
||||||
|
template_file: Path,
|
||||||
sheet_name: str,
|
sheet_name: str,
|
||||||
full_area_name: str,
|
full_area_name: str,
|
||||||
|
from_addr: str,
|
||||||
subject: str,
|
subject: str,
|
||||||
|
name_idx: int,
|
||||||
|
mail_idx: int,
|
||||||
dry_run: bool = False,
|
dry_run: bool = False,
|
||||||
mail_idx: int = 6,
|
|
||||||
name_idx: int = 0,
|
|
||||||
template_file: str = "template.txt",
|
|
||||||
from_addr: str = "bonn@tvstud.de",
|
|
||||||
) -> None:
|
) -> None:
|
||||||
df = pd.read_excel(data_file, sheet_name=sheet_name)
|
df = pd.read_excel(data_file, sheet_name=sheet_name)
|
||||||
today = pd.to_datetime("today").normalize()
|
today = pd.to_datetime("today").normalize()
|
||||||
@ -26,7 +26,7 @@ def read_data(
|
|||||||
if pd.isna(mail):
|
if pd.isna(mail):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with open(template_file) as f:
|
with template_file.open() as f:
|
||||||
template = Template(f.read())
|
template = Template(f.read())
|
||||||
|
|
||||||
msg = template.render(
|
msg = template.render(
|
||||||
@ -37,7 +37,7 @@ def read_data(
|
|||||||
payload = [
|
payload = [
|
||||||
"thunderbird",
|
"thunderbird",
|
||||||
"-compose",
|
"-compose",
|
||||||
f"to={mail},subject={subject},from={from_addr},body='{msg}'",
|
f"to='{mail}',subject='{subject}',from='{from_addr}',body='{msg}'",
|
||||||
]
|
]
|
||||||
if dry_run:
|
if dry_run:
|
||||||
print(payload)
|
print(payload)
|
||||||
@ -51,10 +51,30 @@ def main():
|
|||||||
"--data-file",
|
"--data-file",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=Path("Strukturaufbau.xlsx"),
|
default=Path("Strukturaufbau.xlsx"),
|
||||||
help="Path of the ods/Excel file containing the mapping data",
|
help="Path of the ods/Excel file containing the mapping data."
|
||||||
|
"Defaults to 'Strukturaufbau.xlsx'",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--fromname", type=str, default="TVStud Bonn", help="Sender name to use"
|
"--template-file",
|
||||||
|
type=Path,
|
||||||
|
default=Path("template.txt"),
|
||||||
|
help="Path of the text file containing the template for the mail body. "
|
||||||
|
"Defaults to 'template.txt'.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--from-name",
|
||||||
|
type=str,
|
||||||
|
default="TVStud Bonn",
|
||||||
|
help="Sender name to use. Defaults to 'TVStud Bonn'",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--from-address",
|
||||||
|
type=str,
|
||||||
|
default="bonn@tvstud.de",
|
||||||
|
help="Sender address to use. Defaults to 'bonn@tvstud.de'",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--subject", type=str, default="TVStud Bonn TODO", help="Mail subject to use"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--sheet",
|
"--sheet",
|
||||||
@ -66,7 +86,8 @@ def main():
|
|||||||
"--full-area-name",
|
"--full-area-name",
|
||||||
type=str,
|
type=str,
|
||||||
default=None,
|
default=None,
|
||||||
help="The name of the area to use in the mail (e.g. 'Psychologie' for the sheet 'Psycho')",
|
help="The name of the area to use in the mail (e.g. 'Psychologie' for the sheet 'Psycho'). "
|
||||||
|
"If None, the sheet name is used instead. Defaults to None.",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@ -79,6 +100,19 @@ def main():
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Do a dry run and only print the generated emails to stdout",
|
help="Do a dry run and only print the generated emails to stdout",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--name-idx",
|
||||||
|
type=int,
|
||||||
|
default=0,
|
||||||
|
help="Index of the column containing the names (0-based). Defaults to 0.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--mail-idx",
|
||||||
|
type=int,
|
||||||
|
default=6,
|
||||||
|
help="Index of the column containing the mail addresses (0-based). Defaults to 6.",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.print_sheets or args.sheet is None:
|
if args.print_sheets or args.sheet is None:
|
||||||
@ -90,11 +124,15 @@ def main():
|
|||||||
if args.full_area_name is None:
|
if args.full_area_name is None:
|
||||||
args.full_area_name = args.sheet
|
args.full_area_name = args.sheet
|
||||||
|
|
||||||
read_data(
|
construct_mails(
|
||||||
args.data_file,
|
data_file=args.data_file,
|
||||||
args.sheet,
|
template_file=args.template_file,
|
||||||
args.full_area_name,
|
sheet_name=args.sheet,
|
||||||
subject="TVStud TODO",
|
full_area_name=args.full_area_name,
|
||||||
|
subject=args.subject,
|
||||||
|
from_addr=args.from_address,
|
||||||
|
name_idx=args.name_idx,
|
||||||
|
mail_idx=args.mail_idx,
|
||||||
dry_run=args.dry_run,
|
dry_run=args.dry_run,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user