Initial commit: boarding pass to AirTrail pipeline
Photograph/screenshot a boarding pass, decode its BCBP barcode (PDF417/ Aztec/QR/DataMatrix), fetch the historical flight track from FlightAware the day after the flight, stage it for review, and write it into AirTrail via its REST API on approval. ntfy notifications carry signed Approve/Deny/Investigate actions.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import sqlite3
|
||||
from contextlib import contextmanager
|
||||
|
||||
import config
|
||||
|
||||
SCHEMA = """
|
||||
CREATE TABLE IF NOT EXISTS pending_flights (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'queued'
|
||||
CHECK (status IN ('queued','pending_review','track_unavailable',
|
||||
'approved','rejected','decode_failed')),
|
||||
image_path TEXT NOT NULL,
|
||||
raw_bcbp TEXT,
|
||||
passenger_name TEXT,
|
||||
pnr TEXT,
|
||||
from_iata TEXT,
|
||||
to_iata TEXT,
|
||||
from_icao TEXT,
|
||||
to_icao TEXT,
|
||||
operating_carrier_iata TEXT,
|
||||
operating_carrier_icao TEXT,
|
||||
flight_number TEXT,
|
||||
julian_day INTEGER,
|
||||
flight_date TEXT,
|
||||
known_departure_time TEXT,
|
||||
compartment TEXT,
|
||||
seat TEXT,
|
||||
process_after TEXT,
|
||||
fetch_attempts INTEGER NOT NULL DEFAULT 0,
|
||||
track_coordinates TEXT,
|
||||
track_times TEXT,
|
||||
track_point_count INTEGER,
|
||||
flightaware_url TEXT,
|
||||
airtrail_flight_id INTEGER,
|
||||
parse_warnings TEXT,
|
||||
error_message TEXT,
|
||||
reviewed_at TEXT,
|
||||
approved_at TEXT
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_pending_flights_status_process_after
|
||||
ON pending_flights(status, process_after);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT
|
||||
);
|
||||
"""
|
||||
|
||||
|
||||
def get_connection() -> sqlite3.Connection:
|
||||
config.ensure_dirs()
|
||||
conn = sqlite3.connect(config.DB_PATH, timeout=30)
|
||||
conn.row_factory = sqlite3.Row
|
||||
conn.execute("PRAGMA journal_mode=WAL")
|
||||
conn.execute("PRAGMA foreign_keys=ON")
|
||||
return conn
|
||||
|
||||
|
||||
@contextmanager
|
||||
def connect():
|
||||
conn = get_connection()
|
||||
try:
|
||||
yield conn
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def init_db() -> None:
|
||||
with connect() as conn:
|
||||
conn.executescript(SCHEMA)
|
||||
Reference in New Issue
Block a user