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]

sabbath_school_reproducer.main.main()[source]

Main function that orchestrates the entire process

This function handles command-line arguments, loads configuration, downloads lesson content, and generates PDF output. It also supports reproduction mode for adapting historical lessons to new dates.

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: object

Handles configuration loading and validation for Sabbath School lessons.

get(key, default=None)[source]

Get a config value with a default

get_github_paths()[source]

Generate GitHub repository paths based on configuration

Returns:

Dictionary with GitHub paths

Return type:

dict

load_config()[source]

Load configuration from YAML file

Returns:

Validated configuration dictionary

Return type:

dict

Raises:

Exception – If config loading or validation fails

validate_config(config)[source]

Validates the configuration data

Parameters:

config (dict) – Configuration dictionary

Returns:

Validated configuration dictionary

Return type:

dict

Raises:

ValueError – If validation fails

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: object

Downloads 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

download_markdown(url)[source]

Download markdown content from a URL

Parameters:

url (str) – URL to download markdown from

Returns:

Markdown content, or empty string if download failed

Return type:

str

static get_lesson_range_filename(config)[source]

Generate a filename that includes the lesson range information

Parameters:

config (Config) – Configuration object

Returns:

Filename with lesson range information

Return type:

str

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: object

Combines 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

static create_file_section(filename, content)[source]

Format content as a file section with header

Parameters:
  • filename (str) – Name of the file section

  • content (str) – Content to include in the section

Returns:

Formatted section with header

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: object

Processes markdown files to extract structured content.

static add_new_lines_to_markdown(markdown_content)[source]
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

static process_markdown_file(markdown_file, config=None)[source]

Process the markdown file to extract content

Parameters:
  • markdown_file (str) – Path to the markdown file

  • config (dict, optional) – Configuration dictionary for reproduction

Returns:

Dictionary with extracted content

Return type:

dict

HTML Generator Module

class sabbath_school_reproducer.generator.html_generator.HtmlGenerator[source]

Bases: object

Generates 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

static get_quarter_display(quarter, language_code='en')[source]

Get a formatted display for the quarter

Parameters:
  • quarter (str) – Quarter code (e.g., q1, q2, q3, q4)

  • language_code (str) – Language code for translations

Returns:

Formatted quarter display

Return type:

str

static read_svg_file(filepath)[source]

Read SVG file content from the specified path

Parameters:

filepath (str) – Path to SVG file

Returns:

SVG content or None if error

Return type:

str or None

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: object

Handles 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: object

Handles 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: object

Updates 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: object

Tools 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

static parse_file_sections(markdown_path)[source]

Parse the combined markdown file into its component file sections

Parameters:

markdown_path (str) – Path to the combined markdown file

Returns:

Dictionary mapping file names to content

Return type:

dict