35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Import seed feed sources into the Mobility Workbench source registry."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from app.db import init_db, session_scope # noqa: E402
|
|
from app.source_catalog import default_ingestable_sources_path, import_ingestable_sources # noqa: E402
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description="Import seed ingestable sources into the source registry.")
|
|
parser.add_argument("--csv", dest="csv_path", default=str(default_ingestable_sources_path()), help="CSV path relative to repo root or absolute path")
|
|
parser.add_argument("--no-update", action="store_true", help="Skip rows that already exist instead of updating them")
|
|
args = parser.parse_args()
|
|
|
|
csv_path = Path(args.csv_path)
|
|
if not csv_path.is_absolute():
|
|
csv_path = ROOT / csv_path
|
|
init_db()
|
|
with session_scope() as session:
|
|
result = import_ingestable_sources(session, csv_path, update_existing=not args.no_update)
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|