def handlerPriority(data): words = data.split() names = ["normal", "high", "critical"] score = 100 index = 0 indexList = list() for i, key in enumerate(names): newScore, newList = score_sentence(data, key) if newScore < score: score = newScore index = i indexList = newList if score < 1: words.pop(indexList[0]) priority = index * 50 elif len(words) > 2: skip, priority = parse_number(" ".join(words[1:])) else: priority = 0 try: index = getItem(words[0], todoList) except ValueError: error( "The Index must be composed of numbers. Subitems are separated by a dot." ) return except IndexError: error("The Index for this item is out of range.") return item = todoList for i in index: item = item['items'][i] item['priority'] = priority write_file("todolist.txt", todoList)
def handler_remove(data): skip, number = parse_number(data) if skip: index = number - 1 else: index, index_list = find_reminder(data) if 0 <= index < len(reminderList['items']): info("Removed reminder: \"{0}\"".format( reminderList['items'][index]['name'])) removeReminder(reminderList['items'][index]['uuid']) else: error("Could not find selected reminder")
def _dice_parse(self, s): repeat = 1 howmany = 1 edges = 6 prefix = "" prefix_length = 0 prefix_number = -1 # Iterate string. # Search for number before keywords (edges, times, dices) for word_current in s.split(): parse_result = parse_number(prefix) # make sure, prefix still contains only number-characters if parse_result[0] != prefix_length: # last token not part of number -> reset prefix prefix = word_current prefix_length = 1 continue prefix_number = parse_result[1] if word_current == "edge" or word_current == "edges": edges = prefix_number if word_current == "times": repeat = prefix_number if word_current == "dices": howmany = prefix_number prefix += " " prefix += word_current prefix_length += 1 return {"repeat": repeat, "howmany": howmany, "edges": edges}