diff --git a/README.md b/README.md index b2b9fad..c5cd171 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,15 @@ python3 edit_data_form.py ## Daten eines bestehenden Mitglieds ändern +Eine Nennung des Ordners des Members genügt. +Dann wird stets die aktuelle json-Datei verwendet. + ```bash -MEMBER_FILE= -python3 edit_data_form.py $MEMBER_FILE +python3 edit_data_form.py +``` + +Alternativ kann die json-Datei explizit genannt werden: + +```bash +python3 edit_data_form.py ``` \ No newline at end of file diff --git a/edit_data_form.py b/edit_data_form.py index 68ab61a..7c41f17 100755 --- a/edit_data_form.py +++ b/edit_data_form.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # encoding: utf-8 +import os import npyscreen import json import datetime @@ -65,9 +66,24 @@ class FormApp(npyscreen.NPSAppManaged): def main(*_args): if len(sys.argv) > 1: file_path = pathlib.Path(sys.argv[1]) - if not file_path.exists(): - print("Trying to open nonexistent file. Aborting.") + + if(sys.argv[1].endswith(".json")): + # json file as argument + + if not file_path.exists(): + print("Trying to open nonexistent file. Aborting.") + sys.exit(0) + + elif file_path.is_dir(): + # we want the latest json file in given folder + filesList = [f for f in os.listdir(file_path) if os.path.isfile(os.path.join(file_path, f)) and f.endswith(".json")] + filesList.sort() + file_path = os.path.join(file_path, filesList[-1]) + + else: + print("Please enter a valid json file or the directory containing the json file!") sys.exit(0) + else: file_path = pathlib.Path(pathlib.Path(__file__).absolute().parent, 'example.json')