#!/usr/bin/env python3
"""
quiXzoom Academy — Lektionsgenerator från JSON
Genererar alla HTML-lektioner från academy-lessons-content.json
"""
import json
import os
from pathlib import Path
# Ladda innehåll
with open('academy-lessons-content.json', 'r', encoding='utf-8') as f:
data = json.load(f)
# HTML-mall
HTML_TEMPLATE = '''
{title} — quiXzoom Academy
'''
def generate_content_html(lesson_data):
"""Generera HTML-innehåll för en lektion"""
content = lesson_data['content']
html_parts = []
# Intro
if 'intro' in content:
html_parts.append(f'')
# Tips
if 'tips' in content:
tips_html = '\n'.join([f'• {tip}
' for tip in content['tips']])
html_parts.append(f'\n💡 Tips\n{tips_html}\n
')
# Requirements
if 'requirements' in content:
req_html = '\n'.join([f'{req}' for req in content['requirements']])
html_parts.append(f'')
# Steps
if 'steps' in content:
steps_html = '\n'.join([f'Steg {i+1}: {step}' for i, step in enumerate(content['steps'])])
html_parts.append(f'\n
Steg för steg
\n
\n{steps_html}\n
\n
')
# Factors
if 'factors' in content:
factors_html = '\n'.join([f'{factor}' for factor in content['factors']])
html_parts.append(f'')
# Examples
if 'examples' in content:
examples_html = '\n'.join([f'• {example}
' for example in content['examples']])
html_parts.append(f'\n
Exempel
\n{examples_html}\n')
# Best practices
if 'best_practices' in content:
bp_html = '\n'.join([f'{bp}' for bp in content['best_practices']])
html_parts.append(f'')
# Common errors
if 'common_errors' in content:
errors_html = '\n'.join([f'{error}' for error in content['common_errors']])
html_parts.append(f'')
# Solutions
if 'solutions' in content:
sol_html = '\n'.join([f'{sol}' for sol in content['solutions']])
html_parts.append(f'')
# Safety rules
if 'safety_rules' in content:
rules_html = '\n'.join([f'{rule}' for rule in content['safety_rules']])
html_parts.append(f'')
# Rules
if 'rules' in content:
rules_html = '\n'.join([f'{rule}' for rule in content['rules']])
html_parts.append(f'')
# Strategies
if 'strategies' in content:
strat_html = '\n'.join([f'{strat}' for strat in content['strategies']])
html_parts.append(f'')
# Levels
if 'levels' in content:
levels_html = '\n'.join([f'{level}' for level in content['levels']])
html_parts.append(f'')
# Payment schedule
if 'payment_schedule' in content:
pay_html = '\n'.join([f'{pay}' for pay in content['payment_schedule']])
html_parts.append(f'')
# Deductions
if 'deductions' in content:
ded_html = '\n'.join([f'{ded}' for ded in content['deductions']])
html_parts.append(f'')
# Warning
if 'warning' in content:
html_parts.append(f'\n
⚠️ Viktigt\n
{content["warning"]}
\n
')
# Quiz
if 'quiz' in content:
quiz = content['quiz']
options_html = '\n'.join([
f'\n{chr(65+i)}\n{opt}\n'
for i, opt in enumerate(quiz['options'])
])
correct_feedback = "Bra jobbat!"
wrong_feedback = "Tänk igenom svaret en gång till."
html_parts.append(f'''''')
return '\n\n'.join(html_parts)
def generate_lesson(module, lesson, prev_lesson, next_lesson):
"""Generera en komplett lektion"""
# Bestäm navigation
if prev_lesson:
prev_link = f'/academy/{prev_lesson["module_id"]}/{prev_lesson["id"]}'
prev_text = 'Föregående'
else:
prev_link = '/academy'
prev_text = 'Tillbaka till Academy'
if next_lesson:
next_link = f'/academy/{next_lesson["module_id"]}/{next_lesson["id"]}'
next_text = f'Nästa: {next_lesson["title"]}'
else:
next_link = '/academy'
next_text = 'Tillbaka till Academy'
# Generera innehåll
content_html = generate_content_html(lesson)
# Fyll i mallen
html = HTML_TEMPLATE.format(
title=lesson['title'],
module_title=f'{module["title"]} — {module["description"]}',
duration=lesson['duration'],
level=module['level'],
type=lesson['type'],
content=content_html,
lesson_id=lesson['id'],
prev_link=prev_link,
prev_text=prev_text,
next_link=next_link,
next_text=next_text,
correct_feedback="Bra jobbat!",
wrong_feedback="Tänk igenom svaret en gång till."
)
return html
def main():
"""Generera alla lektioner"""
print("🚀 Genererar quiXzoom Academy-lektioner...")
print("=" * 60)
# Skapa output-mapp
output_dir = Path('academy-output')
output_dir.mkdir(exist_ok=True)
total_lessons = 0
# Gå igenom alla moduler och lektioner
for module_idx, module in enumerate(data['modules']):
module_dir = output_dir / module['id']
module_dir.mkdir(exist_ok=True)
print(f"\n📚 {module['title']}")
for lesson_idx, lesson in enumerate(module['lessons']):
lesson_dir = module_dir / lesson['id']
lesson_dir.mkdir(exist_ok=True)
# Bestäm föregående och nästa lektion
prev_lesson = None
next_lesson = None
if lesson_idx > 0:
prev_lesson = {
'module_id': module['id'],
'id': module['lessons'][lesson_idx - 1]['id'],
'title': module['lessons'][lesson_idx - 1]['title']
}
elif module_idx > 0:
prev_module = data['modules'][module_idx - 1]
prev_lesson = {
'module_id': prev_module['id'],
'id': prev_module['lessons'][-1]['id'],
'title': prev_module['lessons'][-1]['title']
}
if lesson_idx < len(module['lessons']) - 1:
next_lesson = {
'module_id': module['id'],
'id': module['lessons'][lesson_idx + 1]['id'],
'title': module['lessons'][lesson_idx + 1]['title']
}
elif module_idx < len(data['modules']) - 1:
next_module = data['modules'][module_idx + 1]
next_lesson = {
'module_id': next_module['id'],
'id': next_module['lessons'][0]['id'],
'title': next_module['lessons'][0]['title']
}
# Generera lektion
html = generate_lesson(module, lesson, prev_lesson, next_lesson)
# Spara
with open(lesson_dir / 'index.html', 'w', encoding='utf-8') as f:
f.write(html)
total_lessons += 1
print(f" ✅ {lesson['id']}: {lesson['title']}")
print(f"\n{'=' * 60}")
print(f"✅ {total_lessons} lektioner genererade!")
print(f"📁 Sparade i academy-output/")
return total_lessons
if __name__ == "__main__":
main()