Example python scripts

archlinux packages

import subprocess

def packages_list():
    """Yay packages list"""
    packages = subprocess.run(["yay", "-Qu"], capture_output=True, text=True)
    if packages.stdout:
        return packages.stdout
    else:
        return "all packages updated!"

return packages_list()

get the wireless interface

import subprocess
import re

def get_wlan_iface():
    """Get the wireless interface name."""
    interfaces = subprocess.run(
        ["ip", "link", "show"], capture_output=True, text=True
    )
    pattern = r"(^\d+:\s+)(wl.+):"
    for iface in interfaces.stdout.splitlines():
        if re.search(pattern, iface):
            match = re.search(pattern, iface)
    assert match is not None
    return match.group(2)

return get_wlan_iface()