Files
fuzzygraph/enrichers/url_to_headers.py
T
dataforge c9fd4aa84c feat: enrichers, panel de ingest y menu contextual en el grafo
- Añade enricher.go + directorio enrichers/ para enriquecer entidades con fuentes externas.
- Nuevos componentes frontend: IngestPanel (panel de ingesta de datos) y NodeContextMenu (menu contextual sobre nodos del grafo).
- Retira SearchBar y lib/utils.ts; la busqueda se integra dentro de los paneles existentes.
- Ajusta tipos (types.go, types.ts, wailsjs/go) y theming (postcss + app.css + Mantine).
- Actualiza app.go y wails.json para exponer las nuevas capacidades.
- Añade directorio projects/ con estado inicial.
- Rebuild del frontend (dist actualizado).
2026-04-13 23:32:55 +02:00

53 lines
1.4 KiB
Python

"""Enricher: Fetch HTTP headers for a URL and update entity metadata."""
import sys
import json
try:
import httpx
except ImportError:
import urllib.request
def main():
entity = json.load(sys.stdin)
url = (entity.get("metadata") or {}).get("url") or entity.get("name", "")
if not url:
json.dump({"error": "No URL found in entity"}, sys.stdout)
return
try:
try:
resp = httpx.head(url, follow_redirects=True, timeout=10)
headers = dict(resp.headers)
status = resp.status_code
except NameError:
req = urllib.request.Request(url, method="HEAD")
with urllib.request.urlopen(req, timeout=10) as resp:
headers = dict(resp.headers)
status = resp.status
except Exception as e:
json.dump({"error": f"Failed to fetch headers: {e}"}, sys.stdout)
return
# Return metadata update for the source entity
result = {
"entities": [],
"relations": [],
"metadata_update": {
"entity_id": entity["id"],
"metadata": {
"status_code": status,
"server": headers.get("server", ""),
"content_type": headers.get("content-type", ""),
"x_powered_by": headers.get("x-powered-by", ""),
},
},
}
json.dump(result, sys.stdout, ensure_ascii=False)
if __name__ == "__main__":
main()