File size: 1,161 Bytes
1426bed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import annotations

import argparse
import json
import sys
from pathlib import Path


def _repo_root() -> Path:
    return Path(__file__).resolve().parents[2]


def main() -> int:
    repo_root = _repo_root()
    if str(repo_root / "backend") not in sys.path:
        sys.path.insert(0, str(repo_root / "backend"))

    from app.services.trabalhos_tecnicos_importer import DEFAULT_LOCAL_DB_FILE, DEFAULT_SOURCE_XLSX_FILE, build_database_from_xlsx

    parser = argparse.ArgumentParser(description="Importa o Excel de trabalhos tecnicos para um banco SQLite.")
    parser.add_argument(
        "--xlsx",
        default=str(Path.home() / "Downloads" / DEFAULT_SOURCE_XLSX_FILE),
        help="Caminho da planilha xlsx de origem.",
    )
    parser.add_argument(
        "--db",
        default=str(repo_root / "backend" / "local_data" / DEFAULT_LOCAL_DB_FILE),
        help="Caminho do banco SQLite de destino.",
    )
    args = parser.parse_args()

    resultado = build_database_from_xlsx(args.xlsx, args.db)
    print(json.dumps(resultado, ensure_ascii=False, indent=2))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())