INNER CODE UNIT · Python

save_to_csv

cognitivetech/ollama-ebook-summary · book2text.py:154

def save_to_csv(data, output_file):
    with open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(['filename', 'title', 'text', 'len'])
        writer.writerows(data)

def main(input_file, output_dir, output_csv):
    if os.path.exists(output_dir):
        shutil.rmtree(output_dir)
    os.makedirs(output_dir, exist_ok=True)

    file_type = os.path.splitext(input_file)[1][1:]  # Remove the dot


    if file_type == 'epub':
        success = split_epub_by_sections(input_file, output_dir)  # Changed from output_directory to output_dir
        if not success:
            print("Error detected while splitting EPUB. Attempting alternative method with epubunz.py.")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…