def remove_task(bot, update, args):
    '''
    Remove an element from the given list
    '''

    # args is a list: when you insert words separated by a space, it considers the space as a separator and creates a list of all the inserted words
    # to re-create the string, you can simply join the words inserting a space among them

    taskToRemove = ' '.join(args)

    message = ''
    if taskToRemove and taskToRemove.strip() and (not taskToRemove.isspace()):

        if(db_interaction.db_contains(taskToRemove)):
            result = db_interaction.db_remove_task(taskToRemove)

            if (result > 0):
                message = "The task was successfully removed!"
            else:
                message = "No task was deleted due to a problem! Try again!"
        else:
            message = "The task you specified is not in the database!"
    else:
        message = "You did not specify any task!"
    #send the generated message to the user
    bot.sendMessage(chat_id=update.message.chat_id, text=message)
    # send the updated list as a message
    newMessage = "Now the list contains the following items:"
    bot.sendMessage(chat_id=update.message.chat_id, text=newMessage)
    updatedTaskList = db_interaction.get_sorted_tasks_list()
    bot.sendMessage(chat_id=update.message.chat_id, text=updatedTaskList)
def remove_multiple_tasks(bot, update, args):
    '''
    Remove all the elements that contain a provided string
    '''

    # args is a list: when you insert words separated by a space, it considers the space as a separator and creates a list of all the inserted words
    # to re-create the string, you can simply join the words inserting a space among them
    substring = ' '.join(args)
    message = ''

    if substring and substring.strip() and (not substring.isspace()):
        # substring is not None AND substring is not empty or blank AND substring is not only made by spaces

        result = db_interaction.db_remove_multiple_tasks(substring)

        if (result>0):
            message = "The elements were successfully removed!"
        else:
            message = "No task was deleted due to a problem! Try again!"
    else:
        message = "You did not specify any string!"
    # send the generated message to the user
    bot.sendMessage(chat_id=update.message.chat_id, text=message)
    # send the updated list as a message
    newMessage = "Now the list contains the following items:"
    bot.sendMessage(chat_id=update.message.chat_id, text=newMessage)
    updatedTaskList = db_interaction.get_sorted_tasks_list()
    bot.sendMessage(chat_id=update.message.chat_id, text=updatedTaskList)
示例#3
0
def print_sorted_list():
    '''
    Print the elements of the list, sorted in alphabetic order
    '''

    #get the list of tasks from the database
    tasks_list = db_interaction.get_sorted_tasks_list()

    print tasks_list
示例#4
0
def print_sorted_list():
    '''
    Print the elements of the list, sorted in alphabetic order (we order data directly through sql)
    '''

    #get the list of tasks from the database
    tasks_list = db_interaction.get_sorted_tasks_list()

    print tasks_list
示例#5
0
def add():
    todo = str(request.form["todo"])
    try:
        urgent_return = request.form["urgent"]
        if urgent_return == 'on':
            urgent = 1
        else:
            urgent = 0
    except:
        urgent = 0

    if todo:
        result = db_interaction.db_insert_task(todo, urgent)
        if (result > 0):
            tasks = db_interaction.get_sorted_tasks_list()
            return render_template("home.html", tasks=tasks)
def print_sorted_list(bot, update):
    '''
    Print the elements of the list, sorted in alphabetic order
    '''
    tasks_list = db_interaction.get_sorted_tasks_list()
    message = ''
    # check if the list is empty
    if (len(tasks_list) == 0):
        message = "Nothing to do, here!"
    else:
        # we don't want to modify the real list of elements: we want only to print it after sorting
        # there are 2 possibilities:
        # a) using the sort method
        #  temp_tasks_list = tasks_list[:]
        #  temp_tasks_list.sort()
        #  message = temp_tasks_list
        # b) using the sorted method (the sorted method returns a new list)
        message = tasks_list
    bot.sendMessage(chat_id=update.message.chat_id, text=message)
示例#7
0
def home():
    tasks = db_interaction.get_sorted_tasks_list()
    return render_template("home.html", tasks=tasks)
示例#8
0
def delete(task):
    db_interaction.db_remove_task(task)
    tasks = db_interaction.get_sorted_tasks_list()
    return render_template("home.html", tasks=tasks)
示例#9
0
def index():
    #get the ordered list from the database
    tasks_list = db_interaction.get_sorted_tasks_list()
    return render_template('index.html', tasks_list=tasks_list)
示例#10
0
def index():
    task_list = db_interaction.get_sorted_tasks_list()
    return render_template("index.html", tasks=task_list)
示例#11
0
def index():
    #get the ordered list from the database
    tasks_list = db_interaction.get_sorted_tasks_list()
    return render_template('index.html', tasks_list=tasks_list)
示例#12
0
def get_one_task(id):
    tasks = db_interaction.get_sorted_tasks_list()
    one_task = [task for task in tasks if task['id'] == id]
    return jsonify(one_task[0])
示例#13
0
def get_task_list():
    tasks = db_interaction.get_sorted_tasks_list()
    return jsonify(tasks)