diff --git a/.gitignore b/.gitignore index b7faf40..a04f85b 100644 --- a/.gitignore +++ b/.gitignore @@ -205,3 +205,9 @@ cython_debug/ marimo/_static/ marimo/_lsp/ __marimo__/ + +# SQLite database +database/*.db +database/*.sqlite +database/*.sqlite3 + diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..d951d8d --- /dev/null +++ b/init.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +echo "[INFO] Creating virtual environment..." +python3 -m venv .venv +source .venv/bin/activate + +echo "[INFO] Installing dependencies..." +pip install --upgrade pip +pip install -r requirements.txt || echo "[WARN] requirements.txt not found, skipping." + +echo "[INFO] Running database setup..." +python scripts/init_db.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a61cf87 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +# Core tools +typer[all] # For CLI commands +Jinja2 # For static HTML generation +sqlite-utils # Optional: high-level SQLite handling +Flask # For optional lightweight API server + +# Linting / formatting (optional but recommended) +black +flake8 diff --git a/run-import.sh b/run-import.sh new file mode 100755 index 0000000..d951d8d --- /dev/null +++ b/run-import.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +echo "[INFO] Creating virtual environment..." +python3 -m venv .venv +source .venv/bin/activate + +echo "[INFO] Installing dependencies..." +pip install --upgrade pip +pip install -r requirements.txt || echo "[WARN] requirements.txt not found, skipping." + +echo "[INFO] Running database setup..." +python scripts/init_db.py diff --git a/scripts/init_db.py b/scripts/init_db.py new file mode 100644 index 0000000..8a3a89c --- /dev/null +++ b/scripts/init_db.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +import os +import sqlite3 +import re +from pathlib import Path + +LOG_DIR = "/var/log/nginx" +DB_FILE = "database/ngxstat.db" +LOG_FILE_PATTERN = re.compile(r'access\.log(\.\d+)?$') +LOG_FORMAT_REGEX = re.compile( + r'(?P\S+) - (?P\S+) \[(?P