Skip to content

Add Python script for generating interactive HTML articles with OpenRouter API #251818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 18, 2025

This PR adds a complete Python-based solution for generating interactive HTML articles with embedded tests using the OpenRouter API and Claude 3.5 Sonnet model.

Features

🚀 Core Functionality

  • Automated article generation from topics list using OpenRouter API
  • Interactive HTML output with embedded CSS, JavaScript, and quiz functionality
  • Unique file naming and ID generation to prevent conflicts
  • Comprehensive error handling with retry logic and exponential backoff

📚 Article Structure

Each generated article includes:

  • 5-8 structured chapters with educational content
  • 4 mandatory info block types per chapter:
    • 📝 Важно знать (Important to know)
    • 📅 Интересный факт (Interesting fact)
    • 🔢 Статистика (Statistics)
    • Особенность (Special feature)
  • Interactive tests after each chapter with 4 multiple-choice answers
  • Progress tracking with visual progress bar
  • Result calculation and display system

🔧 Technical Implementation

  • Uses anthropic/claude-3-5-sonnet-20240620 model via OpenRouter
  • Reads API key from OPENROUTER_API_KEY environment variable
  • Generates unique id_prefix for each article to avoid HTML ID conflicts
  • Full UTF-8 and emoji support
  • CSS styling with .interactive-container class
  • Self-contained HTML files with embedded JavaScript

Files Added

create_articles.py (268 lines)

Main script with:

  • OpenRouterClient class for API communication
  • ArticleGenerator class for HTML generation and file management
  • Comprehensive error handling and retry logic
  • Test mode for development/validation

topics.txt

Sample topics file with 10 diverse subjects:

Искусственный интеллект в медицине
История развития интернета
Основы квантовой физики
...

test_articles.py (183 lines)

Comprehensive test suite validating:

  • Article generation in test mode
  • Filename generation and sanitization
  • Unique ID prefix generation
  • HTML structure validation

README_articles.md

Complete documentation including:

  • Installation and setup instructions
  • Usage examples and API key configuration
  • Technical details and file structure
  • Troubleshooting guide

Usage

# Set up API key
export OPENROUTER_API_KEY="sk-or-v1-your-key"

# Generate articles from topics.txt
python3 create_articles.py

# Run tests
python3 test_articles.py

Example Output

Generated HTML includes:

<div class="interactive-container">
  <h1>📚 Topic Title</h1>
  
  <div class="progress-bar">
    <div class="progress-fill" id="art_12345678_progress_bar"></div>
  </div>
  
  <div class="chapter">
    <h2>Chapter 1</h2>
    <div class="info-block">📝 <strong>Важно знать:</strong> Key information</div>
    <div class="date-box">📅 <strong>Интересный факт:</strong> Historical details</div>
    <!-- Quiz with 4 options -->
    <div class="quiz-container" data-question="1" data-correct="0">
      <!-- Interactive quiz content -->
    </div>
  </div>
</div>

Quality Assurance

All tests pass - comprehensive validation of core functionality
Error handling - graceful API failure recovery with retries
Unique identifiers - prevents HTML ID conflicts across articles
UTF-8 support - full emoji and international character support
Self-contained output - no external dependencies in generated HTML
Production ready - complete documentation and error messages

This implementation fulfills all requirements from the original specification while adding robust testing and documentation for maintainability.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits June 18, 2025 15:06
…L articles with OpenRouter API

Co-authored-by: artkusama <141212669+artkusama@users.noreply.github.com>
Co-authored-by: artkusama <141212669+artkusama@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Создание генератора интерактивных статей на Python Add Python script for generating interactive HTML articles with OpenRouter API Jun 18, 2025
Copilot finished work on behalf of artkusama June 18, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant