"""Enricher: Fetch URL and produce a text node.""" import sys import json import os sys.path.insert(0, os.path.join(os.environ.get("FN_REGISTRY_ROOT", ""), "python", "functions", "core")) from fetch_and_parse_url import fetch_and_parse_url 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 metadata or name"}, sys.stdout) return text = fetch_and_parse_url(url) result = { "entities": [ { "name": f"Text: {url[:60]}", "type_ref": "text", "description": f"Text extracted from {url}", "tags": ["extracted"], "metadata": { "content_preview": text[:500], "source": url, "char_count": len(text), "full_content": text, }, "notes": "", } ], "relations": [ { "name": "extracted_from", "from_entity": "__NEW_0__", "to_entity": "__SOURCE__", "description": "Text extracted from URL", "weight": 1.0, "tags": [], "notes": "", } ], } json.dump(result, sys.stdout, ensure_ascii=False) if __name__ == "__main__": main()