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 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 addReminder(name, time, uuid, body='', urgency=Notify.Urgency.LOW, hidden=True): """ Queue reminder. Show notification at the specified time. With the given name as title and an optional body for further information. The mandatory is used to identify the reminder and remove it with removeReminder(). If the reminder should show up in the list printed by 'remind print' hidden (default: True) should be set to false. In this case the reminder is requeued at startup. If reminders are used e.g. with a todo list for due dates, hidden should probably be set to true so that the list is not cluttered with automatically created data. If the reminder needs a different priority, it can be set with urgency to critical (=2), high (=1) or normal (=0, default). """ waitTime = time - dt.now() n = Notify.Notification.new(name, body) n.set_urgency(urgency) timerList[uuid] = Timer(waitTime.total_seconds(), showAlarm, [n, name]) timerList[uuid].start() newItem = {'name': name, 'time': time, 'hidden': hidden, 'uuid': uuid} reminderList['items'].append(newItem) reminderList['items'] = sort(reminderList['items']) write_file("reminderlist.txt", reminderList)
def removeReminder(uuid): """ Remove and cancel previously added reminder identified by the given uuid. """ if uuid in timerList: timerList[uuid].cancel() timerList.pop(uuid) for index, e in enumerate(reminderList['items']): if uuid == e['uuid']: reminderList['items'].remove(reminderList['items'][index]) break write_file("reminderlist.txt", reminderList)
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]) write_file("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:]) write_file("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 write_file("todolist.txt", todoList)
def handler_clear(data): reminderList['items'] = [k for k in reminderList['items'] if k['hidden']] write_file("reminderlist.txt", reminderList)