33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import sqlite3
|
|
import sys
|
|
|
|
from src.database import reload_database
|
|
from src.extract import CSVFileError, read_records
|
|
from src.quality import OUTPUT_DIR, build_report, save_reports
|
|
from src.transform import clean_orders
|
|
|
|
|
|
def main() -> int:
|
|
try:
|
|
records = list(read_records())
|
|
accepted, rejected = clean_orders(records)
|
|
report = build_report(accepted, rejected, len(records))
|
|
reload_database(OUTPUT_DIR / "orders.db", accepted)
|
|
except (CSVFileError, sqlite3.Error, OSError) as exc:
|
|
print(f"Загрузка не завершена. {type(exc).__name__}: {exc}", file=sys.stderr)
|
|
return 1
|
|
|
|
try:
|
|
save_reports(accepted, rejected, report)
|
|
except Exception as exc:
|
|
exc.add_note("База уже обновлена. Сохранение файлов отчётов не завершено.")
|
|
raise
|
|
|
|
print(f"Загрузка и экспорт завершены. Прочитано {len(records)}, "
|
|
f"принято {len(accepted)}, отброшено {len(rejected)}.")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|