INNER CODE UNIT · Python
write_csv_header
cognitivetech/ollama-ebook-summary · sum.py:217
def write_csv_header(writer):
"""Write the CSV header with the specified format."""
writer.writerow(["chapter", "level", "title", "text", "text.len", "summary", "summary.len", "time"])
def write_csv_entry(writer, unique_title: str, text: str, summary: str, elapsed_time: float, is_chapter: bool, heading_level: int):
"""Write entry with the specified format."""
# Replace newlines with escaped newlines
escaped_summary = summary.replace('\n', '\\n')
writer.writerow([
is_chapter,
heading_level,
unique_title,
text,
len(text),
escaped_summary,
len(summary),
elapsed_time
])