krz/aws-summary-report
clone: git clone https://gitbay.org/krz/aws-summary-report.git
main: main.py · raw
1import toml
2from utils import send_email
3import importlib
4
5
6def load_sections(section_names, config):
7 report_parts = []
8
9 for name in section_names:
10 try:
11 mod = importlib.import_module(f"sections.{name}")
12 section_text = mod.get_section(config)
13 report_parts.append(section_text)
14 except Exception as e:
15 report_parts.append(f"[ERROR loading section '{name}']: {e}")
16
17 return "\n\n".join(report_parts)
18
19
20def main():
21 config = toml.load("config.toml")
22 sections = config["report"]["sections"]
23
24 body = load_sections(sections, config)
25
26 send_email(
27 smtp_config=config["email"],
28 subject="AWS Daily Report",
29 body=body,
30 recipients=config["recipients"]["emails"],
31 )
32
33 # DEBUG
34 # print(body)
35
36 print("Program completed successfully.")
37
38
39if __name__ == "__main__":
40 main()