controller.utils.emergency_slide_factory
- File:
EuljiroWorship/controller/utils/emergency_slide_factory.py
- Author:
Benjamin Jaedon Choi - https://github.com/saintbenjamin
- Affiliated Church:
The Eulji-ro Presbyterian Church [대한예수교장로회(통합) 을지로교회]
- Address:
The Eulji-ro Presbyterian Church, 24-10, Eulji-ro 20-gil, Jung-gu, Seoul 04549, South Korea
- Telephone:
+82-2-2266-3070
- E-mail:
euljirochurch [at] G.M.A.I.L. (replace [at] with @ and G.M.A.I.L as you understood.)
- License:
MIT License with Attribution Requirement (see LICENSE file for details); Copyright (c) 2025 The Eulji-ro Presbyterian Church.
Generates slide dictionaries for emergency captions.
This module defines controller.utils.emergency_slide_factory.EmergencySlideFactory, a utility that builds slide payloads
consumable by the slide controller / overlay pipeline.
Supported inputs:
Bible references (parsed by
core.utils.bible_parser.parse_reference())Manual fallback captions and messages
Preset responsive readings (교독문) loaded from JSON files
Preset hymns loaded from JSON files
Outputs:
A list of slide dictionaries with keys:
style,caption,headline
Note
Bible verse text is wrapped into smaller chunks (currently
width=60) to avoid overly long single-slide lines.Version display aliases are loaded from
core.config.paths.ALIASES_VERSION_FILE.
- class controller.utils.emergency_slide_factory.EmergencySlideFactory(bible_loader=None)[source]
Bases:
objectFactory for constructing emergency slide blocks.
This class converts user-facing emergency inputs into a list of slide dictionaries suitable for immediate export to the slide controller.
It supports multiple input modes, including:
Bible references (single verse, range, or full chapter)
Manual text fallback
Responsive readings (교독문)
Hymns (찬송가)
Arbitrary manual slide content
Verse-based slides are retrieved via
core.utils.bible_data_loader.BibleDataLoaderand wrapped into screen-friendly chunks using textwrap.wrap.Slide dict schema:
{ "style": str, # e.g., "verse", "lyrics", "greet", ... "caption": str, # title / reference line "headline": str, # main body text shown on screen }
- VERSION_ALIASES
Mapping of Bible version keys to human-readable aliases, loaded from
core.config.paths.ALIASES_VERSION_FILE. Used when rendering verse captions.- Type:
dict
- loader
Bible data loader instance used to retrieve verse text, book names, and chapter metadata. Either provided externally or created internally during initialization.
- Type:
- __init__(bible_loader=None)[source]
Initialize the factory.
Loads Bible version display aliases from
core.config.paths.ALIASES_VERSION_FILEand prepares acore.utils.bible_data_loader.BibleDataLoaderinstance (either the provided one or a default).- Parameters:
bible_loader (BibleDataLoader | None) – Optional custom Bible loader. If None, a default
BibleDataLoader()is created and used.- Returns:
None
- create_from_input(line1, line2, version=None)[source]
Create emergency slides from a pair of user input lines.
Behavior:
If
line1is parsed as a Bible reference (e.g., “요 3:16”, “요한복음 3:16”), this method retrieves the verse text and returns verse-style slides.If the reference represents a full chapter request (
verse_rangelike(1, -1)), it expands the range to the chapter’s maximum verse count when possible.If
line1is NOT a valid reference, it falls back to a single manual slide whereline1becomes the caption andline2becomes the headline.
- Parameters:
line1 (str) – First line of user input. Interpreted as either a Bible reference or a manual caption.
line2 (str) – Second line of user input. Interpreted as either ignored (when the first line is a valid reference) or a manual headline/message.
version (str | None) – Preferred Bible version name to use when resolving verse text. If None, the loader’s default/available version list is used.
- Returns:
A list of slide dictionaries. Returns an empty list if no valid output can be produced (e.g., empty manual input or failed verse load).
- Return type:
list[dict]
- build_bible_slides(book_id, chapter, verses, version=None)[source]
Build verse-style slides for the given Bible location and verse range.
This method attempts to retrieve verse text using
core.utils.bible_data_loader.BibleDataLoader.get_verse(). Ifversionis provided, it tries that version first; otherwise it iterates available versions and returns the first successful slide set.Each verse is wrapped using textwrap.wrap(…, width=60) to avoid overly long single lines, producing multiple slides per verse when needed.
See also
core.config.constants.MAX_CHARS.- Parameters:
book_id (str) – Internal Bible book identifier (e.g., “John”).
chapter (int) – Chapter number.
verses (list[int] | tuple[int, int]) – Verse numbers to include. The implementation currently uses
min(verses)andmax(verses)to define an inclusive range.version (str | None) – Preferred Bible version name. If None, tries multiple versions.
- Returns:
A list of verse-style slide dictionaries. If verse retrieval fails for all attempted versions, returns an empty list.
- Return type:
list[dict]
- create_from_respo(number)[source]
Load a responsive reading (교독문) JSON by number and generate slides.
The expected JSON format contains:
title: str (optional)slides: list of entries, each typically containing:speaker: strheadline: str
For each entry, one slide is created containing a single speaker-response line formatted in an HTML-like style (e.g.,
"<b>...</b>").- Parameters:
number (int) – Responsive reading number (e.g., 123).
- Returns:
A list of slide dictionaries (style “verse”). If loading fails, returns a one-slide fallback with an error message.
- Return type:
list[dict]
- format_responsive_text(slides_raw)[source]
Format responsive reading entries into a single joined string.
Each entry is converted into one line using an HTML-like emphasis for the speaker name:
"<b>{speaker}:</b> {headline}"
- Parameters:
slides_raw (list[dict]) –
Raw entry list, where each entry may include:
speaker: strheadline: str
- Returns:
A newline-joined formatted text block. Empty entries are skipped.
- Return type:
str
- create_from_hymn(number)[source]
Load a hymn JSON by number and split it into lyric slides.
The expected JSON format contains:
“title”: str (optional)
“headline”: str (lyrics text, typically multi-line)
Lyrics are split into chunks of two lines per slide.
- Parameters:
number (int) – Hymn number (e.g., 88).
- Returns:
A list of slide dictionaries with style “lyrics”. If loading fails, returns a one-slide fallback with an error message.
- Return type:
list[dict]
- create_manual_slide(style, caption, text)[source]
Generate slide(s) from manually provided content.
Behavior:
If style is “lyrics”, the input text is split by lines and grouped into 2-line chunks per slide.
For all other styles, a single slide is produced as-is.
- Parameters:
style (str) – Internal slide style (e.g., “verse”, “greet”, “lyrics”).
caption (str) – Caption/title string shown above or alongside the main text.
text (str) – Main body text for the slide(s).
- Returns:
List of slide dictionaries ready to be exported.
- Return type:
list[dict]