diff --git a/main.py b/main.py index 010a953..2aec1f2 100644 --- a/main.py +++ b/main.py @@ -43,16 +43,32 @@ def now(receiver_email: str): generate_email(receiver_email) def generate_email(receiver_email: str): - services.apt.require_root() - if not services.apt.detect_apt(): - print("Apt not found on this system.") - exit(1) - updates = services.apt.check_updates() + #services.apt.require_root() + #if not services.apt.detect_apt(): + # print("Apt not found on this system.") + # exit(1) + #updates = services.apt.check_updates() + + # TODO: Remove this after testing + updates = { + "openssl": { + "security": True, + "installed_version": "1.0.0", + "latest_version": "1.1.0", + "repo": "main", + }, + "vim": { + "security": False, + "installed_version": "2.0.0", + "latest_version": "2.1.0", + "repo": "universe", + } + } # Get how many security updates are available security_updates = 0 for package in updates: - if package["security"]: + if updates[package]["security"]: security_updates += 1 # Get how many total updates are available @@ -60,18 +76,25 @@ def generate_email(receiver_email: str): # Get how many general updates are available general_updates = total_updates - security_updates + if general_updates == 0: + print("No general updates available.") + return + # Get system hostname hostname = gethostname() # Create email subject subject = f"{hostname}> {security_updates} security updates, {general_updates} general updates available" - # Iterate over each security package and create a list of updates in html + chunk = f'' # define chunk + # Iterate over each security package and create a list of updates in html security_chunks = "" for package in updates: - if not package["security"]: + if not updates[package]["security"]: + continue + if security_updates == 0: continue chunk = f''' @@ -81,7 +104,7 @@ def generate_email(receiver_email: str): {package["repo"]} ''' - + security_chunks += chunk security = f''' @@ -104,6 +127,8 @@ def generate_email(receiver_email: str): for package in updates: if package["security"]: continue + if general_updates == 0: + continue chunk = f''' {package}