#!/usr/bin/env python3 # add a crontab entry with crontab -e: # 0 */2 * * * $HOME/.config/nvim/i3/check-updates.py # # create /etc/apt/apt.conf.d/10periodic with: # APT::Periodic::Enable "1"; # APT::Periodic::Update-Package-Lists "1"; # APT::Periodic::AutocleanInterval "7"; # APT::Periodic::Verbose "1"; # import subprocess import pathlib import os CMD = ["apt", "list", "--upgradeable"] def check_updates(): output = str(subprocess.check_output(CMD, stderr=subprocess.DEVNULL)) output = output.splitlines() return len(output[1:-1]) if __name__ == "__main__": pending = check_updates() if pending == 0: result = "" else: result = f"{pending} updates" with open(os.path.join(pathlib.Path.home(), ".pending_updates"), "wt") as fd: fd.write(result)