Cleanup
This commit is contained in:
parent
3973986011
commit
0d73059281
@ -6,16 +6,16 @@ import pandas as pd
|
||||
from jinja2 import Template
|
||||
|
||||
|
||||
def read_data(
|
||||
data_file: str,
|
||||
def construct_mails(
|
||||
data_file: Path,
|
||||
template_file: Path,
|
||||
sheet_name: str,
|
||||
full_area_name: str,
|
||||
from_addr: str,
|
||||
subject: str,
|
||||
name_idx: int,
|
||||
mail_idx: int,
|
||||
dry_run: bool = False,
|
||||
mail_idx: int = 6,
|
||||
name_idx: int = 0,
|
||||
template_file: str = "template.txt",
|
||||
from_addr: str = "bonn@tvstud.de",
|
||||
) -> None:
|
||||
df = pd.read_excel(data_file, sheet_name=sheet_name)
|
||||
today = pd.to_datetime("today").normalize()
|
||||
@ -26,7 +26,7 @@ def read_data(
|
||||
if pd.isna(mail):
|
||||
continue
|
||||
|
||||
with open(template_file) as f:
|
||||
with template_file.open() as f:
|
||||
template = Template(f.read())
|
||||
|
||||
msg = template.render(
|
||||
@ -37,7 +37,7 @@ def read_data(
|
||||
payload = [
|
||||
"thunderbird",
|
||||
"-compose",
|
||||
f"to={mail},subject={subject},from={from_addr},body='{msg}'",
|
||||
f"to='{mail}',subject='{subject}',from='{from_addr}',body='{msg}'",
|
||||
]
|
||||
if dry_run:
|
||||
print(payload)
|
||||
@ -51,10 +51,30 @@ def main():
|
||||
"--data-file",
|
||||
type=Path,
|
||||
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(
|
||||
"--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(
|
||||
"--sheet",
|
||||
@ -66,7 +86,8 @@ def main():
|
||||
"--full-area-name",
|
||||
type=str,
|
||||
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(
|
||||
@ -79,6 +100,19 @@ def main():
|
||||
action="store_true",
|
||||
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()
|
||||
|
||||
if args.print_sheets or args.sheet is None:
|
||||
@ -90,11 +124,15 @@ def main():
|
||||
if args.full_area_name is None:
|
||||
args.full_area_name = args.sheet
|
||||
|
||||
read_data(
|
||||
args.data_file,
|
||||
args.sheet,
|
||||
args.full_area_name,
|
||||
subject="TVStud TODO",
|
||||
construct_mails(
|
||||
data_file=args.data_file,
|
||||
template_file=args.template_file,
|
||||
sheet_name=args.sheet,
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user