Add accent color, email subjects, MD+DOCX outputs, update README
This commit is contained in:
+68
-14
@@ -68,25 +68,40 @@ def _email_logo_html() -> str:
|
||||
"""
|
||||
Return logo HTML for emails.
|
||||
|
||||
Priority:
|
||||
1) EMAIL_LOGO_URL (direct URL to logo image)
|
||||
2) EMAIL_LOGO_PATH (local file; embedded as base64)
|
||||
3) empty string if neither is set.
|
||||
- Priority:
|
||||
1) EMAIL_LOGO_URL (direct URL)
|
||||
2) EMAIL_LOGO_PATH (local file as base64)
|
||||
- Size: max 200% of line height (small).
|
||||
"""
|
||||
logo_url = os.getenv("EMAIL_LOGO_URL")
|
||||
if logo_url:
|
||||
return f'<img src="{logo_url}" alt="Logo" style="max-width:180px; display:block; margin:0 auto 10px auto;"/>'
|
||||
src = logo_url
|
||||
|
||||
logo_path = os.getenv("EMAIL_LOGO_PATH", "/app/src/misc/logo1.png")
|
||||
if not os.path.exists(logo_path):
|
||||
if not logo_url:
|
||||
logo_path = os.getenv("EMAIL_LOGO_PATH", "/app/src/misc/logo1.png")
|
||||
if os.path.exists(logo_path):
|
||||
try:
|
||||
with open(logo_path, "rb") as f:
|
||||
b64 = base64.b64encode(f.read()).decode("utf-8")
|
||||
src = f"data:image/png;base64,{b64}"
|
||||
except Exception:
|
||||
src = None
|
||||
|
||||
if not src:
|
||||
return ""
|
||||
|
||||
try:
|
||||
with open(logo_path, "rb") as f:
|
||||
b64 = base64.b64encode(f.read()).decode("utf-8")
|
||||
return f'<img src="data:image/png;base64,{b64}" alt="Logo" style="max-width:180px; display:block; margin:0 auto 10px auto;"/>'
|
||||
except Exception:
|
||||
return ""
|
||||
# max-height limited to 200% of line height (approx 2em)
|
||||
return (
|
||||
f'<img src="{src}" alt="Logo" '
|
||||
f'style="max-height:2em; width:auto; display:block; margin:0 auto 0.5em auto;" />'
|
||||
)
|
||||
|
||||
|
||||
def _accent_color() -> str:
|
||||
"""
|
||||
Accent color for UI and emails.
|
||||
Default: #7C6DA0
|
||||
"""
|
||||
return os.getenv("EMAIL_ACCENT_COLOR", "#7C6DA0")
|
||||
|
||||
|
||||
def build_template_context(**runtime_kwargs: Any) -> Dict[str, Any]:
|
||||
@@ -100,6 +115,7 @@ def build_template_context(**runtime_kwargs: Any) -> Dict[str, Any]:
|
||||
- EMAIL_CSS_PATH: path to mail_style.css (optional; we inline it)
|
||||
- EMAIL_LOGO_URL: URL for email logo (preferred)
|
||||
- EMAIL_LOGO_PATH: fallback local path for email logo
|
||||
- EMAIL_ACCENT_COLOR: accent color (default #7C6DA0)
|
||||
"""
|
||||
# Load and inline mail_style.css for consistent email styling
|
||||
css_path = os.getenv("EMAIL_CSS_PATH", "/app/src/misc/mail_style.css")
|
||||
@@ -108,10 +124,14 @@ def build_template_context(**runtime_kwargs: Any) -> Dict[str, Any]:
|
||||
# Build logo HTML (URL or local fallback)
|
||||
logo_html = _email_logo_html()
|
||||
|
||||
# Accent color
|
||||
accent = _accent_color()
|
||||
|
||||
ctx: Dict[str, Any] = {
|
||||
"contact_email": os.getenv("EMAIL_CONTACT_ADDRESS", "support@example.com"),
|
||||
"email_css": css_text,
|
||||
"email_logo": logo_html,
|
||||
"accent_color": accent,
|
||||
}
|
||||
|
||||
# Runtime values override env if provided
|
||||
@@ -255,3 +275,37 @@ def send_email(
|
||||
except Exception as e:
|
||||
logger.error("Failed to send email: %s", e)
|
||||
raise EmailError(f"Failed to send email: {e}")
|
||||
|
||||
|
||||
def create_transcript_docx(text: str, filename: str):
|
||||
"""
|
||||
Create a .docx file from plain/markdown transcript text.
|
||||
"""
|
||||
from docx import Document
|
||||
from docx.shared import Pt
|
||||
|
||||
doc = Document()
|
||||
doc.add_heading("Transcript", level=1)
|
||||
|
||||
for line in text.splitlines():
|
||||
p = doc.add_paragraph(line)
|
||||
p.paragraph_format.space_after = Pt(4)
|
||||
|
||||
doc.save(filename)
|
||||
|
||||
|
||||
def create_summary_docx(text: str, filename: str):
|
||||
"""
|
||||
Create a .docx file from summary text.
|
||||
"""
|
||||
from docx import Document
|
||||
from docx.shared import Pt
|
||||
|
||||
doc = Document()
|
||||
doc.add_heading("Summary", level=1)
|
||||
|
||||
for line in text.splitlines():
|
||||
p = doc.add_paragraph(line)
|
||||
p.paragraph_format.space_after = Pt(4)
|
||||
|
||||
doc.save(filename)
|
||||
|
||||
Reference in New Issue
Block a user