diff --git a/scraibe/email_sender.py b/scraibe/email_sender.py index 15aa808..71ca496 100644 --- a/scraibe/email_sender.py +++ b/scraibe/email_sender.py @@ -439,7 +439,7 @@ def _add_transcript_paragraph(doc, line_text, line_number): # ------------ Public DOCX functions ------------ -def create_transcript_docx(text: str, filename: str): +def create_transcript_docx(text: str, filename: str, summary_text: str = ""): """ Create a transcript DOCX with: - 1" margins on all sides @@ -450,10 +450,14 @@ def create_transcript_docx(text: str, filename: str): - Blank spacing between number and text preserved - Page break after every 29 lines - Centered footer: "X of Y" + - If summary_text is provided: + - Page break after transcript + - Centered "SUMMARY" title + - Summary content (markdown-aware) """ + from . import docx_styles + # Step 1: Prepare transcript into pages of 29 lines each - # Each line <= 60 chars total, words preserved, no clipping - # Structure: nested list of paragraphs (pages -> lines) prepared_pages = [] current_page = [] line_count = 0 @@ -535,7 +539,31 @@ def create_transcript_docx(text: str, filename: str): for line_num, line_text in enumerate(page_lines, start=1): _add_transcript_paragraph(doc, line_text, line_number=line_num) - # Step 5: Add footer: "X of Y" centered + # Step 5: If summary_text provided, append it with page break + if summary_text and summary_text.strip(): + # Page break after transcript + p_break = doc.add_paragraph() + pPr = p_break._p.get_or_add_pPr() + for child in list(pPr): + tag = child.tag.split("}")[-1] if "}" in child.tag else child.tag + if tag in ("tabs", "spacing", "ind"): + pPr.remove(child) + page_break = OxmlElement("w:pageBreak") + page_break.set("{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val", "1") + pPr.append(page_break) + + # Centered "SUMMARY" title + title_p = doc.add_paragraph() + title_p.alignment = WD_ALIGN_PARAGRAPH.CENTER + run = title_p.add_run("SUMMARY") + run.font.name = "Courier" + run.font.size = Pt(18) + run.bold = True + + # Add summary content using markdown-aware styling + docx_styles.parse_simple_md_to_paragraphs(doc, summary_text.strip()) + + # Step 6: Add footer: "X of Y" centered section = doc.sections[0] footer = section.footer footer.is_linked_to_previous = False diff --git a/scraibe/tasks.py b/scraibe/tasks.py index 1c713d1..e0cefad 100644 --- a/scraibe/tasks.py +++ b/scraibe/tasks.py @@ -417,12 +417,19 @@ def process_transcription_task( f.write(transcript_text) temp_files.append(md_transcript_path) - # Transcript .docx (standalone, no cover page) + # Transcript .docx (with summary appended if transcript_and_summarize) docx_transcript_path = _safe_filename("TRANSCRIPT", local, date_tag, ".docx") - create_transcript_docx( - transcript_text, - docx_transcript_path, - ) + if summary_text: + create_transcript_docx( + transcript_text, + docx_transcript_path, + summary_text=summary_text, + ) + else: + create_transcript_docx( + transcript_text, + docx_transcript_path, + ) temp_files.append(docx_transcript_path) # JSON as SOURCE @@ -445,25 +452,8 @@ def process_transcription_task( json.dump(json_data, f, indent=2, ensure_ascii=False) temp_files.append(json_path) - # Summary files (if present) - md_summary_path = None - docx_summary_path = None - - if summary_text: - # Summary .md - md_summary_path = _safe_filename("SUMMARY", local, date_tag, ".md") - with open(md_summary_path, "w", encoding="utf-8") as f: - f.write("# Summary\n\n") - f.write(summary_text) - temp_files.append(md_summary_path) - - # Summary .docx (standalone, no cover page) - docx_summary_path = _safe_filename("SUMMARY", local, date_tag, ".docx") - create_summary_docx( - summary_text, - docx_summary_path, - ) - temp_files.append(docx_summary_path) + # No separate summary DOCX/MD when using transcript_and_summarize + # (summary is now embedded in the transcript DOCX) # 5) Build attachments list @@ -474,10 +464,6 @@ def process_transcription_task( json_path, ] - # If summary is present, add summary MD and DOCX - if summary_text: - attachments += [md_summary_path, docx_summary_path] - # 6) Send success email send_success_email( to=email_to,