Unsolicited feedback time!
You probably should write smaller functions that do one thing, instead of one long script.
It's helpful to use type annotations. So you can write like
def something(thing: int, name: str) -> int:
And then static analysis tools (eg: mypy, ty, pylance) can tell you when you messed up
Why not use requests library for network stuff?
You might want to include a pyproject.toml for requirements. uv is also popular for dependency management.
Maybe look into unit testing if this is going to live for a while