# Hatched für Vectorworks: holt das Plugin bei jedem Klick frisch von https://hatched.tech
# (Anleitung: https://hatched.tech/vectorworks). Bitte so lassen, wie es ist.
import subprocess, sys, urllib.request
import vs

HATCHED = "https://hatched.tech"


def hatched_plugin():
    url = HATCHED + "/vectorworks/hatched.py"
    try:
        with urllib.request.urlopen(url, timeout=30) as response:
            return response.read()
    except Exception as error:
        if "CERTIFICATE" not in str(error).upper():
            raise
        return subprocess.run(["curl", "-fsS", url], capture_output=True, check=True).stdout


try:
    code = compile(hatched_plugin(), "hatched.py", "exec")
except Exception as error:
    vs.AlrtDialog("hatched.tech ist nicht erreichbar: " + str(error))
else:
    exec(code, {"__name__": "hatched", "HATCHED": HATCHED})
