Example #1
0
def mode_route(database, user_input):
    input_length = len(user_input)
    if not input_length >= 2 and input_length < 4:  # These commands always take 2-4 inputs
        print('Invalid number of parameters, expected 2-4', end='\n\n')
        return
    command = user_input[0]  # To know which dict we're working with
    mode = user_input[1]
    valid_modes = documentation.get_modes(
        command)  # Returns set of valid modes for given dict command
    if mode in valid_modes:
        mode_function = getattr(item_management,
                                mode + '_mode')  # ie 'add' goes to add_mode()
    else:
        print('Invalid mode', end='\n\n')
        return
    dictionary = database[command]
    input_info = {
        'command':
        command,  # Some containers need different routing within a mode function
        'mode': mode,
        'parameter_length': len(
            user_input[2:]
        )  # For these commands, 'parameters' = inputs following command/mode
    }
    if not mode_function(
            database, dictionary, input_info, *
            user_input[2:]):  # Expand input parameters into arguments
        return
    # Save, sort, and print display
    dict_management.sort_dictionary(database, command)
    file_management.update(database)
    console_display.print_display(database)
    print_mode_success(mode)
Example #2
0
def main():
    database = file_management.load_data(
    )  # If json successfully loaded, use that. Else default to base template.

    # Update backup right after loading (to save state before user performs any actions)
    file_management.update(database, 'data_autobackup.json')

    console_display.print_display(database)

    while True:
        user_input = input().lower()  # Lower for string comparisons
        if not user_input:  # It's possible to enter nothing
            continue
        if not user_input.isascii():
            print('Please only use ASCII characters')
            continue
        user_input = user_input.split(
        )  # Split into a list of space-separated terms
        commands.alias_format(user_input)
        command = user_input[0]
        print()  # Newline to separate input from printing
        try:
            # Try to get corresponding function from commands.py
            # Command functions have '_command' appended to name
            command_function = getattr(commands, command + '_command')
        except AttributeError:  # If function is not found
            print('Invalid command')
            print()  # Newline to separate input from printing
            continue
        command_function(database, user_input)
Example #3
0
def backup_command(database, user_input):
    # ex input: backup
    if dict_management.wrong_parameter_count(len(user_input), 1):
        return
    file_management.update(database, file_name='data_manualbackup.json')
    print(
        'Manual backup successfully created and saved to [data_manualbackup.json]',
        end='\n\n')
Example #4
0
def change_all_daily_dicts(database, mode):
    daily_dictionary_names = documentation.get_daily_dictionary_names()
    daily_dict_item_length = 0
    for dict_name in daily_dictionary_names:
        daily_dict_item_length += len(name_to_container(database, dict_name))
    if daily_dict_item_length == 0:
        print('There are no active daily objectives', end='\n\n')
        return

    # Get confirmation
    while True:
        if mode == 'complete':  # If 'complete', print 'complete', else print '0%' for 'reset'
            print(
                'Set all daily, optional, and active cycle objectives to complete? (y/n)',
                end='\n\n')
        elif mode == 'reset':
            print(
                'Set all daily, optional, and active cycle objectives to 0%? (y/n)',
                end='\n\n')
        user_input = input().lower()
        if user_input == 'y':
            break
        elif user_input == 'n':
            return

    if mode == 'complete':
        for dict_name in daily_dictionary_names:
            # Function expects a dictionary with {database, command, dictionary, parameters} (command = dict name)
            items = {
                'database': database,
                'dictionary': name_to_container(database, dict_name),
                'command': dict_name,
                'parameters': ['complete']
            }
            item_management.setall_mode(items)
    elif mode == 'reset':
        for dict_name in daily_dictionary_names:
            # Function expects a dictionary with {command, dictionary, parameters} (command = dict name)
            items = {
                'database': database,
                'dictionary': name_to_container(database, dict_name),
                'command': dict_name,
                'parameters': ['reset']
            }
            item_management.setall_mode(items)

    for dict_name in daily_dictionary_names:
        sort_dictionary(database, dict_name)
    file_management.update(database)
    console_display.print_display(database)
    print('Dictionary successfully updated', end='\n\n')
Example #5
0
def delete_command(database, user_input):
    # ex input: delete daily
    # ex input: delete all
    if dict_management.wrong_parameter_count(len(user_input), 2):
        return
    delete_mode_input = user_input[1]
    if delete_mode_input not in documentation.get_dictionary_names(
    ) and delete_mode_input != 'all':
        print(
            "Invalid delete mode. Expected a dictionary name (ie daily) or 'all'",
            end='\n\n')
        return
    if not dict_management.delete_dictionary(database, delete_mode_input):
        return
    file_management.update(database)
    console_display.print_display(database)
    print('Successfully deleted the specified', end='\n\n')
Example #6
0
def setdate_command(database, user_input):
    # ex input: setdate 5 26
    if dict_management.wrong_parameter_count(len(user_input), 3):
        return
    input_month = user_input[1]
    input_day = user_input[2]

    if not input_month.isnumeric():
        print('Invalid month. Use numbers in the form MM DD, ie 5 27',
              end='\n\n')
        return
    if not input_day.isnumeric():
        print('Invalid day. Use numbers in the form MM DD, ie 5 27',
              end='\n\n')
        return

    input_month = int(input_month)
    input_day = int(input_day)

    calendar_date = database['settings']['calendar_date']
    if input_month == calendar_date['month'] and input_day == calendar_date[
            'day']:
        print('That date is already set', end='\n\n')
        return
    if input_month > 12 or input_month < 1:
        print('Invalid input. Expected 1-12 range for month', end='\n\n')
        return
    if input_day > 31 or input_day < 1:
        print('Invalid input. Expected 1-31 range for day', end='\n\n')
        return
    if not date_logic.valid_date(input_month, input_day):
        print('Invalid day for that month', end='\n\n')
        return

    if not settings_management.force_date_change_prompt(
            database):  # If they confirm; streak reset, cycles deleted
        console_display.print_display(database)
        return

    database['settings']['calendar_date']['month'] = input_month
    database['settings']['calendar_date']['day'] = input_day

    file_management.update(database)
    console_display.print_display(database)
    print('Date successfully changed', end='\n\n')
Example #7
0
def note_command(database, user_input):
    if not len(user_input) > 1:
        print('Invalid number of parameters, expected at least 2', end='\n\n')
        return
    mode = user_input[1]
    valid_modes = documentation.get_modes('note')
    if mode in valid_modes:
        mode_function = getattr(
            item_management,
            mode + '_note_mode')  # ie 'add' goes to add_note_mode()
    else:
        print('Invalid mode', end='\n\n')
        return
    if not mode_function(database, user_input):
        return
    # Save and print display
    file_management.update(database)
    console_display.print_display(database)
    print_mode_success(mode)
Example #8
0
def setday_command(database, user_input):
    # ex input: setday monday
    if dict_management.wrong_parameter_count(len(user_input), 2):
        return
    input_week_day = user_input[1]
    if input_week_day not in date_logic.get_week_days():
        print('Invalid day. Enter week day name (ie saturday)', end='\n\n')
        return
    if not settings_management.force_date_change_prompt(
            database):  # If they confirm; streak reset, cycles deleted
        console_display.print_display(database)
        return

    week_day_number = date_logic.convert_day(
        input_week_day)  # Convert to #, ie Sunday = 1
    database['settings']['calendar_date']['week_day'] = week_day_number

    file_management.update(database)
    console_display.print_display(database)
    print('Week day successfully changed', end='\n\n')
Example #9
0
def toggle_command(database, user_input):
    # ex input: toggle
    # ex input: toggle welcome
    # ex input: toggle welcome off
    # ex input: toggle defaults
    settings = database['settings']
    input_length = len(user_input)
    if dict_management.wrong_parameter_count(input_length, 1, 2, 3):
        return
    if input_length == 1:  # Just 'toggle'
        documentation.print_toggle_help()
        return

    toggle_input = user_input[1]
    if input_length == 2:  # Either toggling a specific setting or setting to defaults
        if toggle_input in settings:
            settings_management.toggle(database, toggle_input)
        elif toggle_input == 'defaults':
            database['settings'] = file_management.get_template_dict(
            )['settings']
            print('Default settings restored', end='\n\n')
        else:
            print("Invalid setting. See keywords with 'toggle'", end='\n\n')
            return

    elif input_length == 3:  # Specified setting and manual value
        if toggle_input not in settings:
            print("Invalid setting. See keywords with 'toggle'", end='\n\n')
            return
        manual_value = user_input[2]
        if manual_value not in {'on', 'off'}:
            print("Invalid manual value (3rd input). Expected 'on' or 'off'",
                  end='\n\n')
            return
        settings_management.toggle(database, toggle_input, manual_value)
    file_management.update(database)