def handlerAddDue(data): words = data.split() 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] removeReminder(item['uuid']) skip, item['due'] = parse_date(" ".join(words[1:])) urgency = 0 if 'priority' in item: if item['priority'] >= 100: urgency = 2 elif item['priority'] >= 50: urgency = 1 addReminder(name=item['name'], body=item['comment'], uuid=item['uuid'], time=item['due'], urgency=urgency) write_file("todolist.txt", todoList)
def reminder_handler(data): """ Handle the command string for reminders. """ indices = [] score = 100 action = 0 min_args = 0 # Select the best trigger match from the actions list for key in actions: found_match = False for trigger in actions[key]['trigger']: new_score, index_list = score_sentence(data, trigger, distance_penalty=0.5, additional_target_penalty=0, word_match_penalty=0.5) if found_match and len(index_list) > len(indices): # A match for this action was already found. # But this trigger matches more words. indices = index_list if new_score < score: if not found_match: indices = index_list min_args = actions[key]['minArgs'] found_match = True score = new_score action = key if not action: return data = data.split() for j in sorted(indices, reverse=True): del data[j] if len(data) < min_args: error("Not enough arguments for specified command {0}".format(action)) return data = " ".join(data) globals()[action](data)
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 add_plugin_single(name, plugin_to_add, parent): plugin_existing = parent.get_plugins(name) if plugin_existing is None: parent.add_plugin(name, plugin_to_add) else: if not plugin_existing.is_callable_plugin(): parent.update_plugin(name, plugin_to_add) else: error("Duplicated plugin {}!".format(name))
def add_plugin_single(name, plugin_to_add, parent): plugin_existing = parent.get_plugins(name) if plugin_existing is None: parent.add_plugin(name, plugin_to_add) else: if not plugin_existing.is_callable_plugin(): parent.update_plugin(name, plugin_to_add) else: error("Duplicated plugin {}!".format(name))
def _load_add_regular_plugin(self, name, plugin): if name not in self._cache_plugins: self._cache_plugins.update({name: plugin}) return if self._cache_plugins[name].is_composed(): success = self._cache_plugins[name].try_set_default(plugin) if success: return error("Duplicated plugin {}!".format(name))
def handlerRemove(data): skip, number = parseNumber(data) if skip: index = number - 1 else: index, indexList = findReminder(data) if index >= 0 and 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 _load_add_composed_plugin(self, name_first, name_second, plugin_sub): if name_first in self._cache_plugins: plugin_composed = self._cache_plugins[name_first] if not plugin_composed.is_composed(): plugin_composed = self._load_convert_into_composed(name_first, plugin_composed) else: # create new PluginComposed plugin_composed = plugin.PluginComposed(name_first) self._cache_plugins[name_first] = plugin_composed allready_exists = not plugin_composed.try_add_command(plugin_sub, name_second) if allready_exists: error("Duplicated plugin {} {}".format(name_first, name_second))
def handlerRemove(data): try: index = getItem(data.split()[0], todoList) deleteIndex = index.pop() 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['items'].remove(item['items'][deleteIndex]) writeFile("todolist.txt", todoList)
def handlerAddComment(data): words = data.split() 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['comment'] = " ".join(words[1:]) writeFile("todolist.txt", todoList)
def handlerAdd(data): try: index = getItem(data.split()[0], todoList) item = todoList for i in index: item = item['items'][i] data = " ".join(data.split()[1:]) except ValueError: item = todoList except IndexError: error("The Index for this item is out of range.") return newItem = {'complete': 0, 'uuid': uuid4().hex, 'comment': ""} parts = data.split(" - ") newItem['name'] = parts[0] if " - " in data: newItem['comment'] = parts[1] if not 'items' in item: item['items'] = [] item['items'].append(newItem) write_file("todolist.txt", todoList)
def handlerComplete(data): words = data.split() 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] complete = 100 if len(words) > 1: try: complete = min(max(0, int(words[1])), 100) except ValueError: error("The completion level must be an integer between 0 and 100.") return item['complete'] = complete writeFile("todolist.txt", todoList)