def update_mode(database, dictionary, input_info, objective_name, update_value=1): # ex input: daily update wanikani 50 # ex input: daily update wanikani parameter_length = input_info['parameter_length'] if dict_management.wrong_parameter_count(parameter_length, 1, 2): return False command = input_info['command'] # Cycle handled differently if command == 'cycle': if objective_name not in dict_management.get_active_cycle_list(database): # Can't update inactive item print('Cannot update progress for inactive cycle objectives', end='\n\n') return False if parameter_length == 2: # Update value given, will be a string try: # noinspection PyTypeChecker update_value = eval(update_value) except (SyntaxError, NameError): print('Update value must be a number', end='\n\n') return False if not isinstance(update_value, int): print('Update value must be an integer', end='\n\n') return False if objective_name not in dictionary: # If not found, look for as a substring if not (objective_name := dict_management.objective_search(database, dictionary, objective_name)): return False
def set_mode(database, dictionary, input_info, objective_name, set_value): # ex input: daily set wanikani 50 parameter_length = input_info['parameter_length'] if dict_management.wrong_parameter_count(parameter_length, 2): return False command = input_info['command'] # Cycle handled differently try: set_value = eval(set_value) except (SyntaxError, NameError): print('Set value must be a number', end='\n\n') return False if not isinstance(set_value, int): print('Set value must be an integer', end='\n\n') return False if command == 'cycle': if objective_name not in dict_management.get_active_cycle_list(database): # Can't update inactive item print('Cannot update progress for inactive cycle objectives', end='\n\n') return False if objective_name not in dictionary: # If not found, look for as a substring if not (objective_name := dict_management.objective_search(database, dictionary, objective_name)): return False
def reset_mode(database, dictionary, input_info, objective_name): # ex input: daily reset wanikani parameter_length = input_info['parameter_length'] if dict_management.wrong_parameter_count(parameter_length, 1): return False command = input_info['command'] if command == 'cycle': if objective_name not in dict_management.get_active_cycle_list(database): # Can't update inactive item print('Cannot update progress for inactive cycle objectives', end='\n\n') return False if objective_name not in dictionary: # If not found, look for as a substring if not (objective_name := dict_management.objective_search(database, dictionary, objective_name)): return False
def setall_cycle_mode(database, dictionary, setall_value): active_cycle_list = dict_management.get_active_cycle_list(database) if setall_value not in {'complete', 'reset'}: print('Invalid parameter. Expected "complete" or "reset"', end='\n\n') return False if not active_cycle_list: print('There are no active cycle objectives', end='\n\n') return False if setall_value == 'complete': for objective in active_cycle_list: # Set the numerator to the denominator (100%). value is the key's dictionary value value = dictionary[objective] value['numerator'] = value['denominator'] elif setall_value == 'reset': for objective in active_cycle_list: value = dictionary[objective] value['numerator'] = 0 return True
def print_dictionary(database, dict_name): if dict_name == 'daily': daily_dict = database['daily'] if daily_dict: # Skip if empty print_daily_objectives(daily_dict) print() # Extra newline else: # Neither daily nor optionals have any print('There are no daily objectives') elif dict_name == 'optional': optional_dict = database['optional'] if optional_dict: print_optional_objectives(optional_dict) print() # Extra newline else: print('There are no optional objectives') elif dict_name == 'todo': todo_dict = database['todo'] if todo_dict: # Skip if empty print_todo_objectives(todo_dict) print() # Extra newline elif dict_name == 'active_cycle': active_cycle_list = dict_management.get_active_cycle_list(database) if active_cycle_list: # Skip if empty print_active_cycle_objectives(database, active_cycle_list) print() # Extra newline elif dict_name == 'inactive_cycle': inactive_cycle_list = dict_management.get_inactive_cycle_list(database) if inactive_cycle_list: # Skip if empty print_inactive_cycle_objectives(database, inactive_cycle_list) print() # Extra newline elif dict_name == 'longterm': longterm_dict = database['longterm'] if longterm_dict: # Skip if empty print_longterm_objectives(longterm_dict) print() # Extra newline elif dict_name == 'counter': counter_dict = database['counter'] if counter_dict: print_counter_dict(counter_dict) print() # Extra newline