#!/usr/bin/env python3
import sys
import urllib.error
import urllib.request


def main() -> int:
    req = urllib.request.Request("http://checker:9090/check")
    try:
        with urllib.request.urlopen(req, timeout=20) as response:
            sys.stdout.write(response.read().decode("utf-8"))
            return 0
    except urllib.error.HTTPError as exc:
        sys.stdout.write(exc.read().decode("utf-8"))
        return 1
    except urllib.error.URLError as exc:
        print(f"Запрос к чекеру не удался: {exc}")
        return 1


if __name__ == "__main__":
    raise SystemExit(main())
