47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Импорт seed-данных WESP: нормы профилей и нутриенты компонентов."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
|
if str(PROJECT_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
from app import create_app # noqa: E402
|
|
from app.lab.commands.import_seed import import_component_nutrients, import_norm_profiles # noqa: E402
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Import WESP seed CSV from data/seed/")
|
|
parser.add_argument("--norms", action="store_true", help="Import norm profiles")
|
|
parser.add_argument("--nutrients", action="store_true", help="Import component nutrients CSV")
|
|
parser.add_argument("--dry-run", action="store_true", help="Nutrients import dry-run only")
|
|
args = parser.parse_args()
|
|
|
|
if not args.norms and not args.nutrients:
|
|
parser.error("Specify --norms and/or --nutrients")
|
|
|
|
app = create_app()
|
|
with app.app_context():
|
|
if args.norms:
|
|
stats = import_norm_profiles()
|
|
print(
|
|
f"norms: created={stats.profiles_created} updated={stats.profiles_updated} "
|
|
f"norm_rows={stats.norm_rows}"
|
|
)
|
|
if args.nutrients:
|
|
stats = import_component_nutrients(dry_run=args.dry_run)
|
|
print(
|
|
f"nutrients: imported={stats.imported} skipped={stats.skipped} "
|
|
f"unmatched={stats.unmatched}"
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|