#!/usr/bin/python3
"""Render the labwc desktop menu with the current local time and date."""
from datetime import datetime
import os
from pathlib import Path
import xml.etree.ElementTree as ET


def main():
    config = Path(os.environ.get('XDG_CONFIG_HOME') or Path.home() / '.config')
    path = config / 'labwc/menu.xml'
    if not path.is_file():
        path = Path(__file__).resolve().parents[2] / 'etc/skel/.config/labwc/menu.xml'
    root = ET.parse(path).find("menu[@id='root-menu']")
    if root is None:
        raise SystemExit(f'No root-menu found in {path}.')

    menu = ET.Element('openbox_pipe_menu')
    now = datetime.now()
    for item in root:
        if item.get('erdos-status') == 'clock':
            item.set('label', now.strftime('%-I:%M %p  ·  %m/%d/%y'))
            del item.attrib['erdos-status']
        menu.append(item)
    print(ET.tostring(menu, encoding='unicode'))


if __name__ == '__main__':
    main()
