37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
if str(PROJECT_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
from app import create_app
|
|
from app.services.workbook_importer import import_workbook_data
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description="Import workbook data into the configured database.")
|
|
parser.add_argument("--path", default=None, help="Path to the workbook file.")
|
|
parser.add_argument(
|
|
"--replace",
|
|
action="store_true",
|
|
help="Clear imported tables before loading workbook data again.",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
app = create_app()
|
|
with app.app_context():
|
|
workbook_path = args.path or app.config["WORKBOOK_PATH"]
|
|
summary = import_workbook_data(workbook_path=workbook_path, replace_existing=args.replace)
|
|
|
|
print(json.dumps(summary.to_dict(), ensure_ascii=False, indent=2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|