Beispiel #1
0
    def get_task(self, key_task):
        """Returns a task with the specified key from a file (default file=tasks.txt). If task not found,
        return None

        :param
        'key_task': key of the selected tasks

        :return: object Task or None, if task not found in file
        """
        task = None
        scanned_tasks = []

        with open(self.path_to_task_file, 'r') as file:
            for line in file:
                current_task = Task()
                current_task.load(line)

                if current_task.key == key_task:
                    task = current_task
                else:
                    scanned_tasks.append(line)

        self.check_time(task)
        self.save_scanned_tasks(
            scanned_tasks)  # return unsuccessful tasks in file
        return task
Beispiel #2
0
    def get_user_task(self, name_user):
        """Scanned all tasks in file and return list tasks when this user meeting in the attributes 'admins' and 'members'
        (default file=tasks.txt)

        :param
        'name_user': name selected user

        :return: list tasks with this user
        """
        user_tasks = []
        scanned_task = []

        with open(self.path_to_task_file, 'r') as file:
            for line in file:
                task = Task()
                task.load(line)
                if name_user in task.admins:
                    user_tasks.append(task)
                elif name_user in task.members:
                    user_tasks.append(task)
                else:
                    scanned_task.append(line)

        self.save_scanned_tasks(
            scanned_task)  # return unsuccessful tasks in file
        return user_tasks
Beispiel #3
0
    def get_keys_tasks(self):
        """Scanned all tasks in file and return list of task keys (default file=tasks.txt)

        :return: list keys tasks
        """
        keys_task = []
        scanned_task = []

        with open(self.path_to_task_file, 'r') as file:
            for line in file:
                task = Task()
                task.load(line)
                keys_task.append(task.key)
                scanned_task.append(line)

        self.save_scanned_tasks(
            scanned_task)  # return unsuccessful tasks in file
        return keys_task
Beispiel #4
0
    def get_all_tasks(self):
        """Returns all objects tasks of file and clear this (default file=tasks.txt)

        :return: list objects Tasks of file
        """
        tasks = []

        with open(self.path_to_task_file, 'r') as file:
            for line in file:
                task = Task()
                task.load(line)
                tasks.append(task)
        with open(self.path_to_task_file, 'w'):
            pass

        for task in tasks:
            self.check_time(task)

        return tasks
Beispiel #5
0
    def get_free_key_task(self):
        """Generate unique key for tasks. Loads all tasks and returns the first random key. Max key counts = 500 (temp.)

        :return: key in string format or None if count key=500
        """
        keys = []

        try:
            with open(self.path_to_task_file, 'r') as file:
                for line in file:
                    current_task = Task()
                    current_task.load(line)
                    keys.append(current_task.key)
        except:
            pass

        while True:
            if len(keys) == 500:
                return None
            key = random.randint(0, 500)
            if key not in keys:
                return str(key)
Beispiel #6
0
    def get_all_users(self):
        """Scanned all tasks in file and return set name users meeting in the attributes 'admins' and 'members'
        (default file=tasks.txt)

        :return: set name users
        """
        set_users = set()
        scanned_task = []

        with open(self.path_to_task_file, 'r') as file:
            for line in file:
                task = Task()
                task.load(line)
                for user in task.admins:
                    set_users.add(user)
                for user in task.members:
                    set_users.add(user)
                scanned_task.append(line)

        self.save_scanned_tasks(
            scanned_task)  # return unsuccessful tasks in file
        return set_users