Add accent color, email subjects, MD+DOCX outputs, update README
Mirror and run GitLab CI / build (push) Has been cancelled
Ruff / ruff (push) Has been cancelled

This commit is contained in:
admin
2026-06-14 15:49:11 +00:00
parent dc20e9cff0
commit 63cd620b79
11 changed files with 205 additions and 54 deletions
+38 -18
View File
@@ -12,6 +12,7 @@ from .celery_app import celery_app
from .autotranscript import Scraibe
from .misc import setup_logging
from .email_sender import send_email, EmailError, load_template
from .email_sender import create_transcript_docx, create_summary_docx
logger = logging.getLogger("scraibe.tasks")
@@ -19,7 +20,6 @@ logger = logging.getLogger("scraibe.tasks")
def get_queue_position(task_id: str) -> int:
"""
Estimate the job's position in the queue.
This is a simple count of ready/started tasks.
"""
try:
inspect = celery_app.control.inspect()
@@ -38,10 +38,13 @@ def get_queue_position(task_id: str) -> int:
def send_initial_email(to: str, queue_pos: int):
"""
Send initial confirmation email with queue position using HTML template.
Static placeholders (contact_email, css, logo) come from env via load_template.
Send initial confirmation email with queue position.
Subject is customizable via EMAIL_SUBJECT_UPLOAD.
"""
subject = "ScrAIbe: Your transcription request has been received"
subject = os.getenv(
"EMAIL_SUBJECT_UPLOAD",
"ScrAIbe: Your transcription request has been received",
)
# Build plain-text fallback
body = (
@@ -88,10 +91,13 @@ def send_success_email(
task_id: str,
):
"""
Send final email with transcript and attachments using HTML template.
Static placeholders (contact_email, css, logo) come from env via load_template.
Send final email with transcript and attachments.
Subject is customizable via EMAIL_SUBJECT_SUCCESS.
"""
subject = "ScrAIbe: Your transcript is ready"
subject = os.getenv(
"EMAIL_SUBJECT_SUCCESS",
"ScrAIbe: Your transcript is ready",
)
# Build plain-text fallback
body = (
@@ -140,10 +146,13 @@ def send_success_email(
def send_error_email(to: str, error_message: str, task_id: str):
"""
Send error notification email using HTML template.
Static placeholders (contact_email, css, logo) come from env via load_template.
Send error notification email.
Subject is customizable via EMAIL_SUBJECT_ERROR.
"""
subject = "ScrAIbe: Error with your transcription request"
subject = os.getenv(
"EMAIL_SUBJECT_ERROR",
"ScrAIbe: Error with your transcription request",
)
# Build plain-text fallback
body = (
@@ -243,11 +252,17 @@ def process_transcription_task(
# 4) Prepare files for email
attachments = []
# TXT transcript
txt_path = tempfile.mktemp(suffix=".txt")
with open(txt_path, "w", encoding="utf-8") as f:
# Transcript as .md
md_transcript_path = tempfile.mktemp(suffix=".md")
with open(md_transcript_path, "w", encoding="utf-8") as f:
f.write("# Transcript\n\n")
f.write(transcript_text)
attachments.append(txt_path)
attachments.append(md_transcript_path)
# Transcript as .docx
docx_transcript_path = tempfile.mktemp(suffix=".docx")
create_transcript_docx(transcript_text, docx_transcript_path)
attachments.append(docx_transcript_path)
# JSON with diarization
json_data = {
@@ -271,13 +286,18 @@ def process_transcription_task(
json.dump(json_data, f, indent=2, ensure_ascii=False)
attachments.append(json_path)
# MD summary (only when summary is available)
# Summary as .md (only when summary is available)
if summary_text:
md_path = tempfile.mktemp(suffix=".md")
with open(md_path, "w", encoding="utf-8") as f:
md_summary_path = tempfile.mktemp(suffix=".md")
with open(md_summary_path, "w", encoding="utf-8") as f:
f.write("# Summary\n\n")
f.write(summary_text)
attachments.append(md_path)
attachments.append(md_summary_path)
# Summary as .docx
docx_summary_path = tempfile.mktemp(suffix=".docx")
create_summary_docx(summary_text, docx_summary_path)
attachments.append(docx_summary_path)
# 5) Send success email
send_success_email(