aboutsummaryrefslogtreecommitdiff
path: root/main.py
blob: 4a06a939a6c9afe675ba7c9a277d7bbd67ea4dd6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import toml
from utils import send_email
import importlib


def load_sections(section_names, config):
    report_parts = []

    for name in section_names:
        try:
            mod = importlib.import_module(f"sections.{name}")
            section_text = mod.get_section(config)
            report_parts.append(section_text)
        except Exception as e:
            report_parts.append(f"[ERROR loading section '{name}']: {e}")

    return "\n\n".join(report_parts)


def main():
    config = toml.load("config.toml")
    sections = config["report"]["sections"]

    body = load_sections(sections, config)

    send_email(
        smtp_config=config["email"],
        subject="AWS Daily Report",
        body=body,
        recipients=config["recipients"]["emails"],
    )

    # DEBUG
    # print(body)

    print("Program completed successfully.")


if __name__ == "__main__":
    main()