From f2e17ee603147d0b278267ef2fa3fe57d52187d5 Mon Sep 17 00:00:00 2001 From: tyrin Date: Tue, 10 Sep 2024 14:38:23 +0300 Subject: [PATCH] added previous dir choice --- sample_app/management/commands/ingester.py | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/sample_app/management/commands/ingester.py b/sample_app/management/commands/ingester.py index fd253fd..ee15093 100644 --- a/sample_app/management/commands/ingester.py +++ b/sample_app/management/commands/ingester.py @@ -1,5 +1,6 @@ import os import sys +import json import glob import uuid import asyncio @@ -16,11 +17,31 @@ class Command(BaseCommand): def handle(self, *args, **options): + if os.path.exists('config.json'): + with open('config.json', 'r') as config_file: + config = json.load(config_file) + previous_choice = config.get('directory', '') + else: + previous_choice = '' + + #fetching the file list - directory = input("Please enter the path to the directory containing the csv files (or leave empty if the files are in the same directory as this script): ") + directory = input(f"Please enter the path to the directory containing the csv files [{previous_choice}]: ") + if not directory: + directory = previous_choice + + with open('config.json', 'w') as config_file: + json.dump({'directory': directory}, config_file) + + print(f"Selected directory: {directory}") + + csv_files = glob.glob(os.path.join(directory, '*csv*')) self.stdout.write(f"Files found: {len(csv_files)}.") self.stdout.write("Populating the file database...") + + + #initialize the counter new_files_count = 0 #add files as catalogfile instances into the database