Fix this another time, not working at the moment

This commit is contained in:
Uthman Fatih 2025-10-13 21:12:24 +01:00
parent fa8103051f
commit 86618094fc

41
main.py
View File

@ -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'''
<tr>
@ -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'''
<tr>
<td style="border: 1px solid #ddd; padding: 8px;">{package}</td>