diff --git a/setup.py b/setup.py index a54e551..95c6c47 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="CVAT wrapper", - version="0.0.15", + version="0.0.16", author="antwxne", author_email="antoine.desruet@epitech.eu", description="Python wrapper for CVAT API", diff --git a/src/CVAT/_get.py b/src/CVAT/_get.py index c312212..82b7b37 100644 --- a/src/CVAT/_get.py +++ b/src/CVAT/_get.py @@ -30,7 +30,7 @@ def get_user_by_username(self, username: str) -> Optional[BasicUser]: response: Response = self.session.get(url=f'{self.url}/api/users?search={username}&limit=10&is_active=true') return None if response.json()["count"] < 1 else BasicUser.from_json(response.json()["results"][0]) - def get_task_by_name(self, task_name: str): + def get_task_by_name(self, task_name: str) -> Optional[Task]: """ > This function takes a task name as a string and returns a Task object if it exists, otherwise it returns None @@ -43,6 +43,21 @@ def get_task_by_name(self, task_name: str): response: Response = self.session.get(url=f'{self.url}/api/tasks?search={task_name}&limit=10&is_active=true') return None if response.json()["count"] < 1 else Task.from_json(response.json()["results"][0]) + def get_task_by_id(self, task_id: int) -> Task: + """ + > This function takes in a task id and returns a task object + + Args: + task_id (int): The ID of the task you want to get. + + Returns: + A Task object + """ + response: Response = self.session.get(url=f'{self.url}/api/tasks/{task_id}') + if response.status_code != 200: + raise Exception(response.content) + return Task.from_json(response.json()) + def get_map_external_ids_frame(self, task: Union[Task, str]) -> dict: """ > This function takes a task name or a task object and returns a dictionary of image objects @@ -112,7 +127,8 @@ def get_prediction_from_file(self, task: Union[Task, str], prediction_type: str, labels_map: dict = self.get_labels_map(task) return Get.PREDICTION_FACTORY[prediction_type](prediction_json, frame_map, labels_map) - def get_prediction_from_json(self, task: Union[Task, str], prediction_type: str, prediction: Union[dict, list[dict]]) -> IPrediction: + def get_prediction_from_json(self, task: Union[Task, str], prediction_type: str, + prediction: Union[dict, list[dict]]) -> IPrediction: """ > The function takes a task, a prediction type, and a prediction dictionary, and returns a prediction object @@ -161,4 +177,4 @@ def get_project_infos(self, project_name: str) -> dict: response: Response = self.session.get(url=f'{self.url}/api/projects?search={project_name}') if response.status_code != 200: raise Exception(response.content) - return response.json()["results"][0] \ No newline at end of file + return response.json()["results"][0]