INNER CODE UNIT · Python
_classify_url
AgentSkillOS/SkillAnything · scripts/analyze_target.py:61
def _classify_url(url: str, verbose: bool = False) -> str:
"""Fetch a URL and decide whether it is an API (OpenAPI/Swagger) or generic service."""
try:
req = urllib.request.Request(url, method="GET")
req.add_header("User-Agent", "SkillAnything/1.0")
with urllib.request.urlopen(req, timeout=15) as resp:
content_type = resp.headers.get("Content-Type", "")
body = resp.read(64 * 1024).decode("utf-8", errors="replace")
except (urllib.error.URLError, OSError, ValueError) as exc:
if verbose:
print(f"[detect] URL fetch failed: {exc}")
return "service"
openapi_signals = ["openapi", "swagger", '"paths"', '"info"', "operationId"]
hits = sum(1 for s in openapi_signals if s.lower() in body.lower())
if hits >= 2 or "application/json" in content_type and hits >= 1:
if verbose:
print(f"[detect] URL appears to be an OpenAPI/Swagger spec ({hits} signals)")