import otime import cli import sys from rich import inspect def main(): global event while True: print(''' 1. import 2. export 3. edit 4. view tables 5. exit''') try: opt = int(input('Choose an option (1-4): ')) except ValueError: print('Not a valid option!') continue match opt: case 1: import_menu() case 2: export_menu() case 3: print('edit') case 4: table_menu() case 5: print('Goodbye!') sys.exit() def import_menu(): global event while True: try: print(''' 1. import otime file 2. Import xml EntryList 3. Import mtr file (Latin-1) 4. Import mtr file (utf-8) 5. Import ttime db (Latin-1) 6. Import ttime db (utf-8) 7. Import ttime config (Latin-1) 8. Import ttime config (utf-8) 9. Match runners with cards and classes, and o_classes with courses 10. Back''') try: opt = int(input('Choose an option (1-10): ')) except ValueError: print('Not a valid option!') continue match opt: case 1: n = len(event.runners) filename = input('File: ') f = open(filename, 'r') event = otime.Event.from_json(f) nn = len(event.runners) print('Added '+ str(nn-n) +' runners') case 2: n = len(event.runners) filename = input('File: ') f = open(filename, 'r') event.import_xml_entries(f) nn = len(event.runners) print('Added '+ str(nn-n) +' runners') case 3: n = len(event.card_dumps) filename = input('File: ') f = open(filename, 'r', encoding='latin_1') event.import_mtr_file(f) nn = len(event.card_dumps) print('Added '+ str(nn-n) +' cards') case 4: n = len(event.card_dumps) filename = input('File: ') f = open(filename, 'r') event.import_mtr_file(f) nn = len(event.card_dumps) print('Added '+ str(nn-n) +' cards') case 5: n = len(event.runners) filename = input('File: ') f = open(filename, 'r', encoding='latin_1') event.import_ttime_db(f) nn = len(event.runners) print('Added '+ str(nn-n) +' runners') case 6: n = len(event.runners) filename = input('File: ') f = open(filename, 'r') event.import_ttime_db(f) nn = len(event.runners) print('Added '+ str(nn-n) +' runners') case 7: n = len(event.courses) k = len(event.o_classes) filename = input('File: ') f = open(filename, 'r', encoding='latin-1') event.import_ttime_cnf(f) nn = len(event.courses) kk = len(event.o_classes) print('Added '+ str(nn-n) +' courses and '+ str(kk-k) +' classes') case 8: n = len(event.courses) k = len(event.o_classes) filename = input('File: ') f = open(filename, 'r') event.import_ttime_cnf(f) nn = len(event.courses) kk = len(event.o_classes) print('Added '+ str(nn-n) +' courses and '+ str(kk-k) +' classes') case 9: event.match_all() case 10: break except FileNotFoundError: print('No such file or directory!') except IsADirectoryError: print('This is a directory, not a file!') def export_menu(): global event while True: try: print(''' 1. Export otime file 2. Export iof 3.0 xml file 2. Back''') try: opt = int(input('Choose an option (1-2): ')) except ValueError: print('Not a valid option!') continue match opt: case 1: filename = input('File: ') f = open(filename, 'w') f.write(event.create_json_file()) case 2: filename = input('File: ') event.get_xml_res().write(filename) case 3: break except FileNotFoundError: print('No such file or directory!') except IsADirectoryError: print('This is a directory, not a file!') def table_menu(): global event while True: print(''' 1. View runners 2. View courses and classes 3. Show result 4. Show splits 5. back''') try: opt = int(input('Choose an option (1-6): ')) except ValueError: print('Not a valid option!') continue match opt: case 1: cli.print_runners(event.runners) case 2: cli.print_o_classes(event.o_classes) case 3: for o_class in event.o_classes: cli.print_class_result(event.runners, o_class) case 4: for o_class in event.o_classes: cli.print_class_splits(event.runners, o_class) case 5: break if __name__ == "__main__": global event event = otime.Event('0','NoName') main()