reports: fix analysis import error when run as a script\n\n- Prepend project root to sys.path in scripts/generate_reports.py to allow when executed via path\n- Update run-reports.sh to invoke the generator as a module () for robust imports\n- Keeps CLI behavior the same while eliminating 'No module named scripts'
This commit is contained in:
parent
8eec623c92
commit
f0ed112626
2 changed files with 17 additions and 11 deletions
|
@ -29,25 +29,25 @@ fi
|
|||
|
||||
# Generate reports for all domains combined
|
||||
echo "[INFO] Generating aggregate reports..."
|
||||
python scripts/generate_reports.py hourly
|
||||
python scripts/generate_reports.py daily
|
||||
python scripts/generate_reports.py weekly
|
||||
python scripts/generate_reports.py monthly
|
||||
python scripts/generate_reports.py global
|
||||
python -m scripts.generate_reports hourly
|
||||
python -m scripts.generate_reports daily
|
||||
python -m scripts.generate_reports weekly
|
||||
python -m scripts.generate_reports monthly
|
||||
python -m scripts.generate_reports global
|
||||
|
||||
# Generate reports for each individual domain
|
||||
echo "[INFO] Generating per-domain reports..."
|
||||
python scripts/generate_reports.py hourly --all-domains
|
||||
python scripts/generate_reports.py daily --all-domains
|
||||
python scripts/generate_reports.py weekly --all-domains
|
||||
python scripts/generate_reports.py monthly --all-domains
|
||||
python -m scripts.generate_reports hourly --all-domains
|
||||
python -m scripts.generate_reports daily --all-domains
|
||||
python -m scripts.generate_reports weekly --all-domains
|
||||
python -m scripts.generate_reports monthly --all-domains
|
||||
|
||||
# Generate analysis JSON
|
||||
echo "[INFO] Generating analysis files..."
|
||||
python scripts/generate_reports.py analysis
|
||||
python -m scripts.generate_reports analysis
|
||||
|
||||
# Generate root index
|
||||
python scripts/generate_reports.py index
|
||||
python -m scripts.generate_reports index
|
||||
|
||||
# Deactivate to keep cron environment clean
|
||||
if type deactivate >/dev/null 2>&1; then
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import sys
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
@ -11,6 +12,11 @@ import yaml
|
|||
import typer
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
# Ensure project root is importable when running as a script (python scripts/generate_reports.py)
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||
if str(PROJECT_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
DB_PATH = Path("database/ngxstat.db")
|
||||
OUTPUT_DIR = Path("output")
|
||||
TEMPLATE_DIR = Path("templates")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue