def search_regex_search(self): '''This menu is just like `search_text_search` except the user provides a regex pattern instead of a text string ''' text_headers = [self.HEADERS['task_name'], self.HEADERS['notes']] print('SEARCH USING REGEX PATTERN') print("Enter the pattern to search on") input_text = input("> ") pattern = input_text # load csv csvm = CsvManager() csv_data = csvm.load_csv(self.DATASTORE_FILENAME) # perform search matching_records = [] for header in text_headers: matches_for_header = self.get_records_with_pattern( csv_data, header, pattern) if len(matches_for_header) > 0: matching_records.append(matches_for_header) uniques = [] for record in matching_records: if record not in uniques: uniques += record if len(uniques) == 0: print("\nNo matches, returning to search menu") return self.search_entries self.records = uniques self.current_record = 0 return self.present_next_result
def search_text_search(self): '''This is the menu where the user enters a text string and is presented with all entries containing that string in the task name or notes ''' text_headers = [self.HEADERS['task_name'], self.HEADERS['notes']] print('SEARCH USING TEXT STRING') print("Enter the text string to search on") input_text = input("> ") text_string = input_text # load csv csvm = CsvManager() csv_data = csvm.load_csv(self.DATASTORE_FILENAME) # perform search matching_records = [] for header in text_headers: matches_for_header = self.get_records_containing( csv_data, header, text_string) if len(matches_for_header) > 0: matching_records.append(matches_for_header) uniques = [] for record in matching_records: if record not in uniques: uniques += record if len(uniques) == 0: print("\nNo matches, returning to search menu") return self.search_entries self.records = uniques self.current_record = 0 return self.present_next_result
def search_time_spent(self): '''This is the menu where the user enters the number of minutes a task took and be able to choose one to see entries from ''' print('SEARCH BY TIME SPENT') print("Time spent") time_spent = None while time_spent is None: input_text = input("Enter a whole number of minutes (rounded) ") try: time_spent = int(input_text) except ValueError: print("Invalid value") continue # load csv csvm = CsvManager() csv_data = csvm.load_csv(self.DATASTORE_FILENAME) field_title = self.HEADERS['duration'] matching_records = self.get_matching_records(csv_data, field_title, str(time_spent)) if len(matching_records) == 0: print("\nNo matches, returning to search menu") return self.search_entries self.records = matching_records self.current_record = 0 return self.present_next_result
def search_date_range(self): '''This is the menu where the user can enter a from date and to date and get back every entry from within that range ''' print('SEARCH DATE RANGE') start_date = None end_date = None # get start_date while start_date is None: print("Start Date:") user_entry = self.date_entry() if user_entry[0] is not None: # error print(user_entry[0]) continue else: start_date = user_entry[1] # get end_date while end_date is None: print("End Date:") user_entry = self.date_entry() if user_entry[0] is not None: # error print(user_entry[0]) continue else: end_date = user_entry[1] # load csv csvm = CsvManager() csv_data = csvm.load_csv(self.DATASTORE_FILENAME) # loop through every loop in range (inclusive) if end_date < start_date: current_date = end_date end_date = start_date start_date = end_date else: current_date = start_date print("\nShowing entries:") matching_records = [] while current_date <= end_date: # show entries date_string = self.date_to_string(current_date, target='file') matching_records += self.get_matching_records( csv_data, self.HEADERS['date'], date_string) current_date = current_date + datetime.timedelta(days=1) if len(matching_records) == 0: print("\nNo matches, returning to search menu") return self.search_entries self.records = matching_records self.current_record = 0 return self.present_next_result
def delete_current_record(self): print("delete record") match_index = self.current_record record = self.records[match_index] # load te csv csvm = CsvManager() csv_data = csvm.load_csv(self.DATASTORE_FILENAME) # find the row that matches record for row in csv_data: if row == record: # delete that row csv_data.remove(row) break # save the csv csvm.save_csv(csv_data, self.DATASTORE_FILENAME, truncate=True) return self.main_menu
def edit_record(self): print("edit record") print('enter the record number to edit') user_input = input("> ") match_index = int(user_input) - 1 record = self.records[match_index] # get the new values for the record date = None while date is None: print("New date of the Task") user_entry = self.date_entry() if user_entry[0] is not None: # error print(user_entry[0]) continue else: date = user_entry[1] date_string = self.date_to_string(date, target='file') print("New name of the Task") input_text = input("Enter the name of the task > ") task_name = input_text time_spent = None while time_spent is None: print("New time spent") input_text = input("Enter a whole number of minutes (rounded) ") try: time_spent = int(input_text) except ValueError: print("Invalid value") continue print("New notes") input_text = input("(Optional, leave blank for none) ") notes = input_text # load the csv csvm = CsvManager() csv_data = csvm.load_csv(self.DATASTORE_FILENAME) # find the row that matches record for row in csv_data: if row == record: row[self.HEADERS['date']] = date_string row[self.HEADERS['task_name']] = task_name row[self.HEADERS['duration']] = time_spent row[self.HEADERS['notes']] = notes # save the csv csvm.save_csv(csv_data, self.DATASTORE_FILENAME, truncate=True) return self.main_menu
def delete_record(self): print("delete record") print('enter the record number to delete') user_input = input("> ") match_index = int(user_input) - 1 record = self.records[match_index] # load te csv csvm = CsvManager() csv_data = csvm.load_csv(self.DATASTORE_FILENAME) # find the row that matches record for row in csv_data: if row == record: # delete that reow csv_data.remove(row) break # save the csv csvm.save_csv(csv_data, self.DATASTORE_FILENAME, truncate=True) return self.main_menu
def search_exact_date(self): '''This is the menu where the user browses dates and entries and picks the date from a list ''' print("\nSEARCH EXACT DATE") # load the csv csvm = CsvManager() csv_data = csvm.load_csv(self.DATASTORE_FILENAME) date_records = self.get_column(csv_data, self.HEADERS['date'], unique=True) for i, value in enumerate(date_records): print("{}) {}".format(i + 1, value)) selected_date = None while selected_date is None: user_input = input("> ") # perform input validation try: user_input = int(user_input) - 1 except ValueError: print("Invalid value, try again") continue if user_input < 0: print("Value out of range. Try again.") continue try: selected_date = date_records[user_input] except IndexError: print("Value out of range. Try again.") continue # when a date is selected, show all the entries with that date matching_records = self.get_matching_records( csv_data, self.HEADERS['date'], selected_date) self.records = matching_records self.current_record = 0 return self.present_next_result