def create_task(user_id):
    """
    (int) + inputs --> task object
    get a id which is for the user  who is going to make a task
    :param user_id: id for task owner
    :return: task object
    """
    id = task_id()
    title = input('please enter title of your task: ')
    description = input('please enter description of your task: ')
    day = list(
        map(
            int,
            input('when is the due date of this task? (yyyy,mm,dd) ').split(
                ',')))
    due_date = date(day[0], day[1], day[2])
    importance = input('is this task important? (yes / no)(default: no) ')
    urgency = input('is this task urgent? (yes / no)(default: no) ')
    project = input("what is the task's project? (default: inbox)")
    link = input('please enter related links to the task: ')
    location = input('please enter related locations to the task: ')
    set_date = datetime.now().date()
    priority = 4
    if importance == 'yes' and urgency == 'yes':
        priority = 1
    elif importance == 'yes' and urgency == 'no':
        priority = 2
    elif importance == 'no' and urgency == 'yes':
        priority = 3
    else:
        priority = 4
    new_task = Task(id, int(user_id), title, description, due_date, set_date,
                    priority, project, link, location)
    return new_task
예제 #2
0
    def setUpClass(self):
        print(
            "Ejecutando conjunto de tests de peticiones en el servicio de tareas"
        )

        self.app = app.test_client()

        self.user_test = 'jmv74211'
        self.password_user_test = 'jmv74211'

        self.user = '******'
        self.name = 'task name'
        self.description = 'task_description'
        self.estimation = 5
        self.difficulty = 8
        self.max_date = 'task max_date'

        self.task_object_test = Task(self.user, self.name, self.description,
                                     self.estimation, self.difficulty,
                                     self.max_date)

        self.task_id = self.task_object_test.task_id

        self.put_data = json.dumps({
            "user": self.user,
            "name": self.name,
            "description": self.description,
            "estimation": self.estimation,
            "difficulty": self.difficulty,
            "max_date": self.max_date
        })
예제 #3
0
def add_task():
    task_name = input("Task: ")
    task_priority = input("Priority: ")
    task = Task(task_name, task_priority)
    tasks.append(task.__dict__)

    with open("tasks.json", "w") as file_object:
        json.dump(tasks, file_object)
def add_task():
    task_name = input("Task: ")
    task_priority = input("Priority: ")
    task = Task(task_name, task_priority)
    tasks.append(task)

    with open("tasks.txt", "a") as file_object:
        file_object.write(f"{task_name} {task_priority} \n")
예제 #5
0
    def setUpClass(self):
        print(
            'Ejecutando conjunto de tests en funciones locales del servicio de tareas'
        )
        self.user = '******'
        self.name = 'task name'
        self.description = 'task_description'
        self.estimation = 5
        self.difficulty = 8
        self.max_date = 'task max_date'

        self.task_object_test = Task(self.user, self.name, self.description,
                                     self.estimation, self.difficulty,
                                     self.max_date)

        self.task_id = self.task_object_test.task_id
def manage_task(current_user):
    if request.method == 'GET':
        data_list = model.get_all_tasks()
        return jsonify({'result': data_list})

    elif request.method == 'PUT':
        object_task = Task(request.json['user'], request.json['name'],
                           request.json['description'],
                           request.json['estimation'],
                           request.json['difficulty'],
                           request.json['max_date'])

        if (model.insert_task(object_task)):
            return jsonify({
                'result': 'inserted',
                'id': object_task.task_id
            }), 201
        else:
            return jsonify({'result': 'Error, not inserted'}), 400

    elif request.method == 'DELETE':
        delete_task_id = request.json['task_id']

        if (model.delete_task(delete_task_id)):
            return jsonify({'result': 'deleted'}), 204
        else:
            return jsonify({'result': 'Error, not deleted'}), 204

    elif request.method == 'POST':
        if model.exist(request.json['task_id']):
            new_data = {
                "task_id": request.json['task_id'],
                "user": request.json['user'],
                "name": request.json['name'],
                "description": request.json['description'],
                "estimation": request.json['estimation'],
                "difficulty": request.json['difficulty'],
                "max_date": request.json['max_date']
            }

            model.update_task(request.json['task_id'], new_data)

            return jsonify({'status': "updated", 'result': new_data}), 200

        else:
            return jsonify({'result': 'no content'}), 204
def choose_from_task_list(user):
    """
    (user object) --> (task object)
    just a menu to show tasks in a list so user can choose one
    called by task_menu function
    """
    print('which task you want to edit or share?\n'
          '** enter 0 if you want to go to TASK menu')
    with open("task_list.csv", 'r') as f:
        reader = csv.reader(f, delimiter=',')
        lines = []
        i = 1
        for line in reader:
            if line[1] == user.user_id and line[11] == '1' and line[10] == '0':
                """
                line[1]: task owner's id
                line[10]: task status attribute (0 means undone)
                line[11]: task delete attribute (1 means enable)
                user can only edit undone and enable tasks
                """
                print(f'{i}-{line[2:10]}')
                i += 1
                lines.append(line)
    try:
        n = int(input('enter number: ')) - 1
    except ValueError:
        print('Only integers are allowed!')
        logging.error(
            'invalid input in choose task from list menu: not a number')
        choose_from_task_list(user)
    else:
        if n == -1:
            task_menu(user)
        else:
            task = Task(lines[n][0], lines[n][1], lines[n][2], lines[n][3],
                        lines[n][4], lines[n][5], lines[n][6], lines[n][7],
                        lines[n][8], lines[n][9], lines[n][10], lines[n][11])
            return task
예제 #8
0
def simulation(numSeconds, pagesPerMinute):
    """Performs the modeling of average printer wait time"""

    labprinter = Printer(pagesPerMinute)
    printQueue = Queue()
    waitingtimes = []

    for currentSecond in range(numSeconds):

        if newPrintTask():
            task = Task(currentSecond)
            printQueue.enqueue(task)

        if ((not labprinter.busy()) and (not printQueue.isEmpty())):
            nexttask = printQueue.dequeue()
            waitingtimes.append(nexttask.waitTime(currentSecond))
            labprinter.startNext(nexttask)

        labprinter.tick()

    averageWait = sum(waitingtimes) / len(waitingtimes)
    print("Average Wait %6.2f seconds %3d tasks remaining." %
          (averageWait.printQueue.size()))
예제 #9
0
        self._password = val

    def __add_user_in_database(self):
        values = (self._name, self._password, self._task_table)
        self._db.insert_data(table=User.TABLE_NAME, values=values)

    def select_some_task(self, condition="1=1"):
        return self._db.select_data(table=self._task_table,
                                    condition=condition)

    def add_task(self, task):
        task.add_task_in_table()

    def delete_task(self, task):
        task.delete_task()

    def delete_user(self):
        condition = f"name='{self._name}'"
        self._db.drop_table(table_name=self._task_table)
        self._db.delete(table_name="users", condition=condition)


if __name__ == '__main__':
    person1 = User(name="yasha12", password="******")
    task = Task(date="1984-11-12",
                short_name="test functionality",
                description="dadfasdfa",
                task_table_name=person1._task_table)
    print(person1.select_some_task())
    person1.delete_user()
예제 #10
0
from task_class import Task

user_input = ""
to_do = []

while user_input != "q":

    if user_input == "1":

        name = input("Enter task: ")
        priority = input("Enter high, medium, or low priority: ")

        tasks = Task(name, priority)
        to_do.append(tasks)

        with open("tasks.txt", "a") as file_object:
            file_object.write(f"{name} -- {priority} \n")

    elif user_input == "3":

        for index in range(0, len(to_do)):
            print(
                f"{index +1} - {to_do[index].name} - {to_do[index].priority}")

    elif user_input == "2":

        for index in range(0, len(to_do)):
            print(
                f"{index +1} - {to_do[index].name} - {to_do[index].priority}")

        delete_task = int(
예제 #11
0
def task_menu(user):
    print('TASK menu\n'
          '1-add new task\n'
          '2-share or edit existing task\n'
          '3-show all undone tasks in calendar\n'
          '4-show tasks\n'
          '5-change password\n'
          '6-log out\n'
          '7-delete account')
    share_exist = False
    with open('share_task.csv', 'r') as st:
        reader = csv.reader(st, delimiter=',')
        for line in reader:
            if line[2] == user.username:
                print('8-check shared task')
                share_exist = True
                break
    try:
        task_input = int(input('- '))
    except ValueError:
        print('Only Integers are allowed!')
        logging.error('invalid input in task menu: not a number')
    else:
        if task_input == 1:
            new_task = create_task(user.user_id)
            add_task_to_file(new_task)
            logging.info('new task added')
            print('new task added')
            task_menu(user)
        elif task_input == 2:
            task = choose_from_task_list(user)
            edit_task_menu(task, user)
        elif task_input == 3:
            in_calendar(user.user_id)
            task_menu(user)
        elif task_input == 4:
            show_task_menu(user)
            task_menu(user)
        elif task_input == 5:
            current_password = input('enter your current password: '******'utf8')).hexdigest()
            if hashed_pwd == user.password:
                new_password = input('enter new password: '******'confirm new password: '******'password changed')
            task_menu(user)
        elif task_input == 6:
            print(f'{user.username} logged out successfully.')
            logging.info('user logged out')
            exit()
        elif task_input == 7:
            user = User.delete_account(user)
            print(f'{user.username} account deleted successfully.')
            logging.info('user deleted account')
            exit()
        elif task_input == 8:
            if share_exist:
                with open('share_task.csv', 'r') as st:
                    reader = csv.reader(st, delimiter=',')
                    share_task_list = []
                    for line in reader:
                        if line[2] == user.username:
                            share_task_list.append(line)
                print('which task you want to check?')
                for i in range(len(share_task_list)):
                    print(
                        f'{i + 1}-{share_task_list[i][1]} --> {share_task_list[i][3:6]}'
                    )
                try:
                    share_input = int(input('- '))
                except ValueError:
                    print('Only integers are allowed!')
                    logging.error(
                        'invalid input in task menu/share: not a number')
                else:
                    task = share_task_list[share_input - 1]
                    accept_deny = input(
                        'do you want to accept this task?(yes/no) ').lower()
                    if accept_deny == 'yes':
                        set_date = datetime.now()
                        with open('task_list.csv') as tl:
                            task_id = sum(1 for line in tl)
                        share_task = Task(task_id, int(user.user_id), task[3],
                                          task[4], task[5], set_date, task[6],
                                          task[7], task[8], task[9])
                        add_task_to_file(share_task)
                        # change check from 0 to 1 and accept/deny from 0 to 1 which means accepted
                        with open('share_task.csv', 'r') as st:
                            reader = csv.reader(st, delimiter=',')
                            lines = []
                            for line in reader:
                                if line[0] == task[0]:
                                    line[10] = 1
                                    line[11] = 1
                                lines.append(line)
                        with open("share_task.csv", 'w', newline='') as st:
                            writer = csv.writer(st, delimiter=',')
                            writer.writerows(lines)
                    elif accept_deny == 'no':
                        # just change check from 0 to 1
                        with open('share_task.csv', 'r') as st:
                            reader = csv.reader(st, delimiter=',')
                            lines = []
                            for line in reader:
                                if line[0] == task[0]:
                                    line[11] = 1
                                lines.append(line)
                        with open("share_task.csv", 'w', newline='') as st:
                            writer = csv.writer(st, delimiter=',')
                            writer.writerows(lines)
                    else:
                        print(
                            'Invalid Input! --> you should enter "yes" or "no"'
                        )
                        logging.warning(
                            'wrong input for accept or deny share task')
            else:
                print('Invalid input: number does not exist in menu!')
                logging.warning(
                    'invalid input: enter 8 in task menu when there was no shared task'
                )
            task_menu(user)
예제 #12
0
def edit_task_menu(task, user):
    """
    (user object) and (task object) --> nothing
    a menu for edit and share tasks part
    called by task_menu function
    """
    print('what change you want to apply?\n'
          '1-postpone\n'
          '2-report if the task is done\n'
          '3-edit title\n'
          '4-edit description\n'
          '5-edit priority\n'
          '6-edit link\n'
          '7-edit location\n'
          '8-share task\n'
          '9-delete task\n'
          '10-go to TASK menu')
    try:
        edit_input = int(input('- '))
    except ValueError:
        print('Only integers are allowed!')
        logging.error('invalid input in edit task menu: not a number')
    else:
        if edit_input == 1:
            new_due_date = input('enter new due date: ')
            task.postpone(new_due_date)
            save_task(task)
            logging.info('task postponed')
            print(f'{task.title} is postponed to {task.due_date}')
            choose_from_task_list(user)
        elif edit_input == 2:
            task.done()
            save_task(task)
            logging.info('task is done')
            print(f'{task.title} is done!')
            choose_from_task_list(user)
        elif edit_input == 3:
            new_title = input('enter new title: ')
            task.edit_title(new_title)
            save_task(task)
            logging.info("task's title edited")
            choose_from_task_list(user)
        elif edit_input == 4:
            new_description = input('enter new description: ')
            task.edit_description(new_description)
            save_task(task)
            logging.info("task's description edited")
            choose_from_task_list(user)
        elif edit_input == 5:
            try:
                new_priority = int(
                    input('enter new priority:\n'
                          '1- important & urgent\n'
                          '2- not important but urgent\n'
                          '3- important but not urgent\n'
                          '4- not important & not urgent\n'
                          '- '))
            except ValueError:
                print('Only integers are allowed!')
                logging.error('invalid input in priority input: not a number')
                edit_task_menu(task, user)
            else:
                if new_priority in [1, 2, 3, 4]:
                    task.edit_priority(new_priority)
                    save_task(task)
                    logging.info("task's priority edited")
                else:
                    print(
                        'invalid input: you should give a number between 1 to 4'
                    )
                    logging.warning(
                        'invalid input in priority input: unavailable number in menu'
                    )
                choose_from_task_list(user)
        elif edit_input == 6:
            new_link = input('enter new link: ')
            task.edit_link(task, new_link)
            save_task(task)
            logging.info("task's link edited")
            choose_from_task_list(user)
        elif edit_input == 7:
            new_location = input('enter new location: ')
            task.edit_location(new_location)
            save_task(task)
            logging.info("task's location edited")
            choose_from_task_list(user)
        elif edit_input == 8:
            print('who do you want to share your task with?')
            share_user_list = []
            with open('account.csv', 'r') as ac:
                reader = csv.reader(ac, delimiter=',')
                i = 1
                for line in reader:
                    if line[1] != user.username and line[1] != 'username':
                        print(
                            f'{i}-{line[1]}'
                        )  # to make a list of usernames as menu to choose
                        share_user_list.append(line[1])
                        i += 1
            receiver_input = int(input("- ")) - 1
            receiver = share_user_list[receiver_input]
            with open('share_task.csv') as st:
                shared_task_id = sum(
                    1 for line in
                    st)  # to count how many share task exist plus one!
            shared = Task.share(task, user.username, receiver, shared_task_id)
            with open("share_task.csv", 'a', newline='') as share:
                writer = csv.writer(share, delimiter=',')
                writer.writerow(shared)
            logging.info('new share task added')
            choose_from_task_list(user)
        elif edit_input == 9:
            task = Task.delete(task)
            save_task(task)
            logging.info('task deleted')
            task_menu(user)
        elif edit_input == 10:
            logging.info('exit edit task menu')
            task_menu(user)
        else:
            print('invalid input: number does not exist in menu')
            logging.warning(
                'invalid input in edit task menu: unavailable number in menu')