import argparse import os import switch_client import todo from menu import get_menu_items, get_site_links_html, get_treeframe_url def main(): parser = argparse.ArgumentParser(description="Log in to the switch and discover its menu tree.") parser.add_argument("--dump-html", metavar="DIR", help="Save fetched HTML pages into this directory for debugging.") args = parser.parse_args() session = switch_client.get_session() if args.dump_html: os.makedirs(args.dump_html, exist_ok=True) root_html = switch_client.fetch(session, "/") with open(os.path.join(args.dump_html, "root.html"), "w", encoding="utf-8") as f: f.write(root_html) treeframe_url = get_treeframe_url(session) site_links_html = get_site_links_html(session, treeframe_url) with open(os.path.join(args.dump_html, "site_links.html"), "w", encoding="utf-8") as f: f.write(site_links_html) items = get_menu_items(session) for item in items: print(f"{' ' * item.depth}{item.label} -> {item.href}") todo.refresh_todo(items) print(f"\nWrote {todo.TODO_PATH}") if __name__ == "__main__": main()