257 lines
3.5 KiB
Python
257 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
WiFi GPS Mapper
|
|
|
|
HTML Report Generator
|
|
|
|
Запуск:
|
|
|
|
python reports/main.py
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
import shutil
|
|
|
|
from reports.database import connect
|
|
|
|
from reports.config import DATABASE_FILE
|
|
|
|
from reports.template import (
|
|
ReportContext,
|
|
)
|
|
|
|
from reports.dashboard import (
|
|
generate_dashboard,
|
|
generate_capture_sessions,
|
|
)
|
|
|
|
from reports.session_page import (
|
|
build_all_session_pages,
|
|
)
|
|
|
|
|
|
# ============================================================
|
|
# Output directory
|
|
# ============================================================
|
|
|
|
OUTPUT_DIR = (
|
|
Path(__file__).parent
|
|
/ "output"
|
|
)
|
|
|
|
OUTPUT_DIR.mkdir(
|
|
parents=True,
|
|
exist_ok=True,
|
|
)
|
|
|
|
|
|
# ============================================================
|
|
# Helpers
|
|
# ============================================================
|
|
|
|
def save_text(
|
|
|
|
filename: Path,
|
|
|
|
text: str,
|
|
|
|
):
|
|
|
|
filename.parent.mkdir(
|
|
parents=True,
|
|
exist_ok=True,
|
|
)
|
|
|
|
filename.write_text(
|
|
|
|
text,
|
|
|
|
encoding="utf-8",
|
|
|
|
)
|
|
|
|
# ============================================================
|
|
# Copy static resources
|
|
# ============================================================
|
|
|
|
def copy_static():
|
|
|
|
source = (
|
|
Path(__file__).parent
|
|
/ "static"
|
|
)
|
|
|
|
destination = (
|
|
OUTPUT_DIR
|
|
/ "static"
|
|
)
|
|
|
|
if destination.exists():
|
|
|
|
shutil.rmtree(
|
|
destination
|
|
)
|
|
|
|
if source.exists():
|
|
|
|
shutil.copytree(
|
|
source,
|
|
destination
|
|
)
|
|
|
|
# ============================================================
|
|
# Build report
|
|
# ============================================================
|
|
|
|
def build_report():
|
|
|
|
print()
|
|
|
|
print("=" * 60)
|
|
|
|
print(" WiFi GPS Mapper")
|
|
|
|
print(" HTML Report Generator")
|
|
|
|
print("=" * 60)
|
|
|
|
print()
|
|
|
|
if not DATABASE_FILE.exists():
|
|
|
|
raise FileNotFoundError(
|
|
|
|
f"Database not found:\n{DATABASE_FILE}"
|
|
|
|
)
|
|
|
|
print("Opening database...")
|
|
|
|
conn = connect(DATABASE_FILE)
|
|
|
|
context = ReportContext(
|
|
"static"
|
|
)
|
|
|
|
print("Copying static resources...")
|
|
|
|
copy_static()
|
|
|
|
try:
|
|
|
|
#
|
|
# Dashboard
|
|
#
|
|
|
|
print("Generating dashboard...")
|
|
|
|
dashboard = generate_dashboard(
|
|
conn,
|
|
context,
|
|
)
|
|
|
|
save_text(
|
|
|
|
OUTPUT_DIR / "index.html",
|
|
|
|
dashboard,
|
|
|
|
)
|
|
|
|
#
|
|
# Capture Sessions
|
|
#
|
|
|
|
print("Generating capture sessions page...")
|
|
|
|
capture_sessions = generate_capture_sessions(
|
|
conn,
|
|
context,
|
|
)
|
|
|
|
save_text(
|
|
|
|
OUTPUT_DIR / "capture_sessions.html",
|
|
|
|
capture_sessions,
|
|
|
|
)
|
|
|
|
#
|
|
# Sessions
|
|
#
|
|
|
|
print("Generating session pages...")
|
|
|
|
generated = build_all_session_pages(
|
|
conn,
|
|
context,
|
|
)
|
|
|
|
print()
|
|
|
|
print(
|
|
|
|
f"Generated {len(generated)} session pages."
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
conn.close()
|
|
|
|
print()
|
|
|
|
print("Done.")
|
|
|
|
print()
|
|
|
|
print(
|
|
|
|
"Dashboard:"
|
|
|
|
)
|
|
|
|
print(
|
|
|
|
OUTPUT_DIR / "index.html"
|
|
|
|
)
|
|
|
|
print()
|
|
|
|
print(
|
|
|
|
"Output directory:"
|
|
|
|
)
|
|
|
|
print(
|
|
|
|
OUTPUT_DIR.resolve()
|
|
|
|
)
|
|
|
|
print()
|
|
|
|
print("=" * 60)
|
|
|
|
print()
|
|
|
|
# ============================================================
|
|
# MAIN
|
|
# ============================================================
|
|
|
|
def main():
|
|
|
|
build_report()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
|
|