From 892e8057c9ca3b7666fe0134c698f46f7865c1e4 Mon Sep 17 00:00:00 2001 From: alpcentaur Date: Thu, 14 Dec 2023 17:17:58 +0100 Subject: [PATCH] some more error handling for the interface commands --- fdb_spider_interface.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/fdb_spider_interface.py b/fdb_spider_interface.py index 177c37c..0920031 100644 --- a/fdb_spider_interface.py +++ b/fdb_spider_interface.py @@ -286,10 +286,15 @@ if __name__ == '__main__': answer = "The room_id to update the tags was not found" if user_input_list[0] == 'printtags': - if len(user_input_list[1]) >= 1: + try: + room_id_to_print_tags = user_input_list[1] + except: + answer = "after the command printtags, the second argument has to be the room id.. use printrooms and look up the id of the room you want to print the tags" + room_id_to_print_tags = 'NONE' + if room_id_to_print_tags not 'NONE': try: - room_file = open('rooms/' + user_input_list[1] + '.txt', 'r') + room_file = open('rooms/' + room_id_to_print_tags + '.txt', 'r') room_info_raw = room_file.read() room_file.close() room_info = room_info_raw.split('§%§%') @@ -301,7 +306,6 @@ if __name__ == '__main__': except Exception as e: print('error opening, original error is:', e) answer = "The room_id to get the tags was not found" - if user_input_list[0] == 'printcommands': @@ -344,9 +348,10 @@ if __name__ == '__main__': answer = str(room_list) if user_input_list[0] == 'updaterooms': - if len(user_input_list[1]) >= 1: - room_to_update = user_input_list[1] - else: + try: + if len(user_input_list[1]) >= 1: + room_to_update = user_input_list[1] + except Exception as e: room_to_update = 'NONE' room_list = [] rooms = os.listdir('rooms') @@ -427,10 +432,12 @@ if __name__ == '__main__': except Exception as e: print("probably i was not there in last page, original error is:", e) - if room_was_found == False: - answer = 'Den angegebenen Raum gibt es nicht.. Versuche es noch einmal mit -> updaterooms ' - if room_was_found == True: - answer = "Ich update die Rooms auf Basis der Daten in fdb-spider/spiders/output.." + if room_to_update == 'NONE': + answer = 'No room was specified, all rooms will get an update based on the data available' + if room_was_found == False and room_to_update != 'NONE': + answer = 'The room you specified does not exist, or there are no rooms configured, try the command without argument -> updaterooms' + if room_was_found == True and room_to_update != 'NONE': + answer = "I am updating the specified room based on the data in fdb-spider/spiders/output.." if user_input_list[0] == 'printfdbs':