Modules
This section provides documentation for the internal modules and classes of the Sabbath School Lessons Reproducer.
Core Modules
Generator Modules
Utility Modules
Main Module
Sabbath School Lesson Downloader and Generator
This script downloads lesson content from GitHub and generates a PDF.
Usage: python3 main.py config.yaml [–debug] [–debug-html-only]
Configuration Module
Configuration Module for Sabbath School Lessons
This module handles loading and validating configuration from a YAML file.
- class sabbath_school_reproducer.config.Config(config_path)[source]
Bases:
objectHandles configuration loading and validation for Sabbath School lessons.
- get_github_paths()[source]
Generate GitHub repository paths based on configuration
- Returns:
Dictionary with GitHub paths
- Return type:
dict
Downloader Module
GitHub Content Downloader for Sabbath School Lessons
This module handles downloading lesson content from the GitHub repository.
- class sabbath_school_reproducer.downloader.GitHubDownloader(github_paths, config=None)[source]
Bases:
objectDownloads Sabbath School lesson content from GitHub repository.
- static check_existing_file(filename, force_overwrite=False)[source]
Check if the file already exists and prompt for overwrite
- Parameters:
filename (str) – Path to the file
force_overwrite (bool) – Whether to force overwrite without prompting
- Returns:
True if should proceed with download, False otherwise
- Return type:
bool
- download_json(url)[source]
Download and parse JSON from a URL
- Parameters:
url (str) – URL to download JSON from
- Returns:
Parsed JSON, or None if download failed
- Return type:
dict
- download_lesson_data()[source]
Download all lesson data from GitHub repository
- Returns:
Dictionary containing all downloaded content
- Return type:
dict
- Raises:
Exception – If download of contents.json fails
Aggregator Module
Content Aggregator Module for Sabbath School Lessons
This module combines downloaded content into a single markdown file.
- class sabbath_school_reproducer.aggregator.ContentAggregator[source]
Bases:
objectCombines downloaded lesson content into a single markdown file.
- static combine_lesson_content(lesson_data, output_path)[source]
Combine all lesson content into a single markdown file
- Parameters:
lesson_data (dict) – Dictionary containing all downloaded content
output_path (str) – Path to save the combined markdown file
- Returns:
Path to the combined markdown file
- Return type:
str
Processor Module
Markdown Processor for Sabbath School Lessons
This module processes markdown files, extracting lesson content, front matter, and back matter.
- class sabbath_school_reproducer.processor.MarkdownProcessor[source]
Bases:
objectProcesses markdown files to extract structured content.
- static adjust_dates(lessons, config)[source]
Adjust lesson dates based on the quarter_start_date in config
- Parameters:
lessons (list) – List of lesson dictionaries
config (dict) – Configuration dictionary with reproduction settings
- Returns:
Updated list of lesson dictionaries with adjusted dates
- Return type:
list
- static extract_and_remove_date(markdown_text, language_code='en')[source]
Extract date from markdown and return the text with the date removed
- Parameters:
markdown_text (str) – The markdown text to process
language_code (str) – The language code
- Returns:
(extracted_date, cleaned_text)
- Return type:
tuple
- static parse_file_sections(content)[source]
Extract content from different file sections marked with special headers
- Parameters:
content (str) – Combined markdown file content
- Returns:
(lessons_content, frontmatter_content, backmatter_content)
- Return type:
tuple
- static parse_lessons(markdown_content, language_code='en')[source]
Parse the markdown content to extract lessons using a line-by-line approach
- Parameters:
markdown_content (str) – Markdown content containing lessons
language_code (str) – Language code for translations
- Returns:
List of lesson dictionaries
- Return type:
list
- static parse_questions_from_markdown(markdown_content, language_code='en')[source]
Parse questions from markdown content.
- Parameters:
markdown_content (str) – Markdown content containing questions
language_code (str) – Language code for translations
- Returns:
List of question dictionaries
- Return type:
list
HTML Generator Module
- class sabbath_school_reproducer.generator.html_generator.HtmlGenerator[source]
Bases:
objectGenerates HTML content for PDF generation with incremental approach.
- static add_section(content_parts, dynamic_css, state, section_name, section_html, start_on_odd=True, reset_counter=False)[source]
Adds a section to the document, ensuring it starts on the correct page
- Parameters:
content_parts (list) – List of HTML content parts
dynamic_css (str) – CSS content with modifications
state (dict) – Current state tracking page numbers, etc.
section_name (str) – Name of the section for comments
section_html (str) – HTML content for the section
start_on_odd (bool) – Whether section should start on odd-numbered page
reset_counter (bool) – Whether to reset page counter for this section
- Returns:
(updated content_parts, updated dynamic_css, updated state)
- Return type:
tuple
- static convert_markdown_to_html(markdown_content)[source]
Convert markdown to HTML with table support
- Parameters:
markdown_content (str) – Markdown content
- Returns:
HTML content
- Return type:
str
- static create_back_cover(back_cover_svg_path=None)[source]
Creates the back cover page HTML using the SVG from file if provided
- Parameters:
back_cover_svg_path (str, optional) – Path to back cover SVG
- Returns:
HTML for back cover
- Return type:
str
- static create_backmatter_html(backmatter_content)[source]
Creates HTML for the back matter section with table support
- Parameters:
backmatter_content (str) – Back matter markdown content
- Returns:
HTML for back matter
- Return type:
str
- static create_cover_page(front_cover_svg_path=None, config=None)[source]
Creates the cover page HTML using the SVG from file if provided
- Parameters:
front_cover_svg_path (str, optional) – Path to front cover SVG
config (dict, optional) – Configuration dictionary
- Returns:
HTML for cover page
- Return type:
str
- static create_debug_html_with_css(content_parts, dynamic_css)[source]
Creates HTML with current content parts and CSS
- Parameters:
content_parts (list) – List of HTML content parts
dynamic_css (str) – CSS content with modifications
- Returns:
Complete HTML string
- Return type:
str
- static create_frontmatter_html(frontmatter_content)[source]
Creates HTML for the front matter section with table support
- Parameters:
frontmatter_content (str) – Front matter markdown content
- Returns:
HTML for front matter
- Return type:
str
- static create_lesson_html(lesson, language_code='en')[source]
Creates HTML for a single lesson with improved formatting for title and date
- Parameters:
lesson (dict) – Lesson dictionary
language_code (str) – Language code for translations
- Returns:
HTML for lesson
- Return type:
str
- static create_table_of_contents(lessons, language_code='en', config=None)[source]
Creates the table of contents HTML with links to lessons
- Parameters:
lessons (list) – List of lesson dictionaries
language_code (str) – Language code for translations
config (dict, optional) – Configuration dictionary containing language_config_path
- Returns:
HTML for table of contents
- Return type:
str
- static fix_markdown_lists(markdown_content)[source]
Fix markdown list rendering by indenting all non-numbered list item lines, but only if at least one numbered list item exists in the content.
- Parameters:
markdown_content (str) – Markdown content with or without numbered lists
- Returns:
Fixed markdown content with proper indentation for list continuity
- Return type:
str
- static generate_html(content_data, front_cover_svg_path=None, back_cover_svg_path=None, config=None)[source]
Generate complete HTML document from content data with incremental approach
- Parameters:
content_data (dict) – Dictionary with content data
front_cover_svg_path (str, optional) – Path to front cover SVG
back_cover_svg_path (str, optional) – Path to back cover SVG
config (dict, optional) – Configuration dictionary
- Returns:
Complete HTML document
- Return type:
str
PDF Generator Module
PDF Generator for Sabbath School Lessons
This module handles the final conversion from HTML to PDF with specific pagination fixes.
- class sabbath_school_reproducer.generator.pdf_generator.PdfGenerator[source]
Bases:
objectHandles conversion of HTML to PDF with pagination control.
- static add_css_for_pagination(output_path)[source]
Create a CSS file with pagination rules
- Parameters:
output_path (str) – Directory to save the CSS file
- Returns:
Path to the generated CSS file
- Return type:
str
- static count_pages_in_document(document)[source]
Count the number of pages in a WeasyPrint document
- Parameters:
document (Document) – WeasyPrint document
- Returns:
Number of pages
- Return type:
int
- static create_blank_page_pdf(output_path)[source]
Generate a blank page PDF
- Parameters:
output_path (str) – Path to save the blank page PDF
- Returns:
Path to the generated PDF
- Return type:
str
- static create_section_document(html_content)[source]
Create a WeasyPrint document for a section
- Parameters:
html_content (str) – HTML content
- Returns:
WeasyPrint document
- Return type:
Document
- static generate_pdf(html_content, output_pdf, config=None)[source]
Converts HTML content to PDF with targeted pagination fixes
- Parameters:
html_content (str) – The complete HTML document
output_pdf (str) – Path to save the PDF file
config (dict, optional) – Configuration dictionary
- Returns:
Path to the generated PDF
- Return type:
str
CSS Styles Module
CSS Styles for Sabbath School Lessons PDF
This module defines the CSS styles used in the generated PDF.
- class sabbath_school_reproducer.generator.css_styles.CssUpdater[source]
Bases:
objectHandles CSS style updates with dynamic content based on configuration.
- static apply_color_theme(css_template, color_theme)[source]
Apply color theme to CSS template
- Parameters:
css_template (str) – Original CSS template string
color_theme (dict) – Color theme dictionary
- Returns:
Updated CSS template with applied color theme
- Return type:
str
- static get_quarter_display(config)[source]
Get the formatted quarter and year display
- Parameters:
config (dict) – Configuration dictionary
- Returns:
Formatted quarter display
- Return type:
str
- static load_color_theme(theme_path)[source]
Load color theme from a YAML file
- Parameters:
theme_path (str) – Path to the color theme YAML file
- Returns:
Color theme dictionary or None if file not found
- Return type:
dict
- static update_css_template(css_template, config, lesson_data=None)[source]
Update CSS template with configuration data and color theme
- Parameters:
css_template (str) – Original CSS template string
config (dict) – Configuration dictionary
lesson_data (dict, optional) – Optional lesson data dictionary
- Returns:
Updated CSS template string
- Return type:
str
SVG Updater Module
Dynamic SVG Updater for Sabbath School Lessons
This module updates SVG files with dynamic content based on configuration.
- class sabbath_school_reproducer.generator.svg_updater.SvgUpdater[source]
Bases:
objectUpdates SVG files with dynamic content based on configuration.
- QUARTER_MONTHS = {'q1': 'January - March', 'q2': 'April - June', 'q3': 'July - September', 'q4': 'October - December'}
- QUARTER_NAMES = {'q1': 'FIRST QUARTER', 'q2': 'SECOND QUARTER', 'q3': 'THIRD QUARTER', 'q4': 'FOURTH QUARTER'}
- static get_quarter_title(config, lesson_data)[source]
Get the quarter title from either config or lesson data
- Parameters:
config (dict) – Configuration dictionary
lesson_data (dict) – Lesson data dictionary
- Returns:
Quarter title
- Return type:
str
- static update_svg_with_config(svg_path, config, lesson_data=None, is_temporary=False)[source]
Update SVG file with configuration data
- Parameters:
svg_path (str) – Path to SVG file
config (dict) – Configuration dictionary
lesson_data (dict, optional) – Optional lesson data dictionary
is_temporary (bool) – Whether this is a temporary file
- Returns:
Path to updated SVG file
- Return type:
str
Debug Tools Module
Debug Tools for Sabbath School Lesson Downloader
This module provides tools to parse and debug the combined markdown file.
- class sabbath_school_reproducer.utils.debug_tools.DebugTools[source]
Bases:
objectTools for debugging and inspecting markdown content.
- static extract_section(markdown_path, section_name)[source]
Extract a specific section from the combined markdown file
- Parameters:
markdown_path (str) – Path to the combined markdown file
section_name (str) – Name of the section to extract (e.g., ‘front-matter.md’)
- Returns:
Content of the specified section, or None if not found
- Return type:
str or None
- static generate_debug_html(markdown_path, output_path=None)[source]
Generate a more sophisticated debug HTML from the combined markdown file
- Parameters:
markdown_path (str) – Path to the combined markdown file
output_path (str, optional) – Path to save the HTML file
- Returns:
Path to the generated HTML file
- Return type:
str