From 9fcd7c159a3999cacc34c9385ab68d79dbfcc4c0 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Sun, 19 Mar 2023 09:49:10 +0100 Subject: [PATCH] add input file argument for import script --- bulk_import.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bulk_import.py b/bulk_import.py index 92f698b..b924e5a 100644 --- a/bulk_import.py +++ b/bulk_import.py @@ -1,8 +1,9 @@ - -import argparse -import yaml from dotenv import load_dotenv load_dotenv() + +import sys +import yaml + from sqlalchemy.orm import sessionmaker from truthinquiry.ext.database.models import * from truthinquiry.ext.database.sa import engine @@ -126,7 +127,7 @@ def bulk_import(data): for lid in lm.get_used_lids(): print("lid :"+ str(lid)) - session.add(Locale(lid)); + session.add(Locale(lid)) for text in TEXT_LIST: print("Text : "+str(text)) @@ -163,6 +164,8 @@ def bulk_import(data): session.add(room) session.commit() -file = open("bulk_data.yml", "r") - -bulk_import(yaml.load(file, yaml.Loader)) +if len(sys.argv) <= 1: + print("Please enter input file") +else: + file = open(sys.argv[1], "r") + bulk_import(yaml.load(file, yaml.Loader))