Esempio n. 1
0
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)
Esempio n. 2
0
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)