reorg content graph

This commit is contained in:
LUIS NOVO 2024-10-28 16:31:22 -03:00
parent 3f997aa22c
commit 669891617b
4 changed files with 281 additions and 0 deletions

View file

@ -0,0 +1,28 @@
from loguru import logger
from open_notebook.graphs.content_processing.state import SourceState
def extract_txt(state: SourceState):
"""
Parse the text file and print its content.
"""
return_dict = {}
if (
state.get("file_path") is not None
and state.get("identified_type") == "text/plain"
):
logger.debug(f"Extracting text from {state.get('file_path')}")
file_path = state.get("file_path")
if file_path is not None:
try:
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()
logger.debug(f"Extracted: {content[:100]}")
return_dict["content"] = content
except FileNotFoundError:
raise FileNotFoundError(f"File not found at {file_path}")
except Exception as e:
raise Exception(f"An error occurred: {e}")
return return_dict