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
|
# Generate reports for all domains combined
|
||||||
echo "[INFO] Generating aggregate reports..."
|
echo "[INFO] Generating aggregate reports..."
|
||||||
python scripts/generate_reports.py hourly
|
python -m scripts.generate_reports hourly
|
||||||
python scripts/generate_reports.py daily
|
python -m scripts.generate_reports daily
|
||||||
python scripts/generate_reports.py weekly
|
python -m scripts.generate_reports weekly
|
||||||
python scripts/generate_reports.py monthly
|
python -m scripts.generate_reports monthly
|
||||||
python scripts/generate_reports.py global
|
python -m scripts.generate_reports global
|
||||||
|
|
||||||
# Generate reports for each individual domain
|
# Generate reports for each individual domain
|
||||||
echo "[INFO] Generating per-domain reports..."
|
echo "[INFO] Generating per-domain reports..."
|
||||||
python scripts/generate_reports.py hourly --all-domains
|
python -m scripts.generate_reports hourly --all-domains
|
||||||
python scripts/generate_reports.py daily --all-domains
|
python -m scripts.generate_reports daily --all-domains
|
||||||
python scripts/generate_reports.py weekly --all-domains
|
python -m scripts.generate_reports weekly --all-domains
|
||||||
python scripts/generate_reports.py monthly --all-domains
|
python -m scripts.generate_reports monthly --all-domains
|
||||||
|
|
||||||
# Generate analysis JSON
|
# Generate analysis JSON
|
||||||
echo "[INFO] Generating analysis files..."
|
echo "[INFO] Generating analysis files..."
|
||||||
python scripts/generate_reports.py analysis
|
python -m scripts.generate_reports analysis
|
||||||
|
|
||||||
# Generate root index
|
# Generate root index
|
||||||
python scripts/generate_reports.py index
|
python -m scripts.generate_reports index
|
||||||
|
|
||||||
# Deactivate to keep cron environment clean
|
# Deactivate to keep cron environment clean
|
||||||
if type deactivate >/dev/null 2>&1; then
|
if type deactivate >/dev/null 2>&1; then
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -11,6 +12,11 @@ import yaml
|
||||||
import typer
|
import typer
|
||||||
from jinja2 import Environment, FileSystemLoader
|
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")
|
DB_PATH = Path("database/ngxstat.db")
|
||||||
OUTPUT_DIR = Path("output")
|
OUTPUT_DIR = Path("output")
|
||||||
TEMPLATE_DIR = Path("templates")
|
TEMPLATE_DIR = Path("templates")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue