Beispiel #1
0
def main(change_input):
    '''Main function for handling CLI input.
    '''
    global A
    global B
    if change_input:
        #Logic for handling the editing of list A
        if (change_input.upper() == 'A'):
            while True:
                print('')
                A = click.prompt(
                    'Please enter a new list of time ranges. Seperate by a comma if you wish to enter\nmore than one ',
                    type=str,
                    default='eg. 10:00-10:30, 11:45-12:00, etc...')
                print('')
                valid, msg = valid_input(A)
                if (valid):
                    print('List A now contains the following time ranges:')
                    for entry in msg:
                        print(entry)
                    print('')
                    A = msg
                    break
                print('')
                print(msg)
                print('')
                print('List was not in the right format. Examples are:')
                print('8:30-10:00, 22:00-22:05, 00:12-00:46')
                print('5:00-5:30, 6:00-7:00')
                print('')
            main()
        #Logic for handling the editing of list B
        elif (change_input.upper() == 'B'):
            while True:
                print('')
                B = click.prompt(
                    'Please enter a new list of time ranges. Seperate by a comma if you wish to enter\nmore than one ',
                    type=str,
                    default='eg. 10:00-10:30, 11:45-12:00, etc...')
                print('')
                valid, msg = valid_input(B)
                if (valid):
                    print('List B now contains the following time ranges:')
                    for entry in msg:
                        print(entry)
                    print('')
                    B = msg
                    break
                print('')
                print(msg)
                print('')
                print('List was not in the right format. Examples are:')
                print("8:30-10:00, 22:00-22:05, 00:12-00:46")
                print('5:00-5:30, 6:00-7:00')
                print('')
            main()
        #Logic for handling the executing of 'run' command
        elif (change_input.lower() == 'run'):
            try:
                results = subtract_time_ranges(A, B)
            except:
                print(
                    'Whoops, an error occurred subtracting these times. Please try new times.'
                )
                main()
            print('\nList A: ')
            for entry in A:
                print(' ' + entry)
            print('\n--minus--\n')
            print('List B: ')
            for entry in B:
                print(' ' + entry)
            print('\nAnswer:')
            for result in results:
                print(result)
            print('')
            main()
        elif (change_input.lower() == 'quit'):
            sys.exit()
            return
    main()
Beispiel #2
0
 def test_subtract_time_ranges_05(self):
     A = ['22:00-23:50']
     B = ['22:03-22:10', '22:30-22:35', '23:40-23:50']
     output = ['22:00-22:03', '22:10-22:30', '22:35-23:40']
     self.assertEqual(subtract_time_ranges(A, B), output)
Beispiel #3
0
 def test_subtract_time_ranges_03(self):
     A = ['9:00-11:00', '13:00-15:00']
     B = ['9:00-9:15', '10:00-10:15', '12:30-16:00']
     output = ['09:15-10:00', '10:15-11:00']
     self.assertEqual(subtract_time_ranges(A, B), output)
Beispiel #4
0
 def test_subtract_time_ranges_04(self):
     A = ['9:00-11:00', '13:00-15:00']
     B = ['9:00-9:15', '9:20-9:45', '13:00-15:00']
     output = ['09:15-09:20', '09:45-11:00']
     self.assertEqual(subtract_time_ranges(A, B), output)
Beispiel #5
0
 def test_subtract_time_ranges_02(self):
     A = ['9:00-10:00', '10:00-11:00']
     B = ['9:00-9:30']
     output = ['09:30-10:00', '10:00-11:00']
     self.assertEqual(subtract_time_ranges(A, B), output)