Добавили пагинацию для тегов

This commit is contained in:
2025-10-29 16:07:06 +03:00
parent e14972c8a2
commit ddec6094c2
2 changed files with 18 additions and 9 deletions

View File

@@ -58,7 +58,7 @@ class ClockifyAPI(ClockifyConfig):
tag = [tag for tag in tags if tag.id == tag_id] tag = [tag for tag in tags if tag.id == tag_id]
if not tag: if not tag:
tag = self.get_tags(True, tag_id=tag_id) tag = self.get_tags(True, tag_id=tag_id, **{"page-size": self.tags_count})
if tag: if tag:
db.insert_tags([tag] if isinstance(tag, Tag) else tag) db.insert_tags([tag] if isinstance(tag, Tag) else tag)
from config import red from config import red
@@ -104,16 +104,25 @@ class ClockifyAPI(ClockifyConfig):
name: str - optional name: str - optional
archived: bool - optional archived: bool - optional
page-size: int - optional page-size: int - optional
page: int - optional
""" """
if is_updating: if is_updating:
page = 1
kwargs["page"] = page
tags = requests.get(self.base_url + self.tags_url, params={"sort-column": "name", "sort-order": "descending", **kwargs}, headers={"X-API-KEY": self.token}).json() tags = requests.get(self.base_url + self.tags_url, params={"sort-column": "name", "sort-order": "descending", **kwargs}, headers={"X-API-KEY": self.token}).json()
if tag_id: while len(tags) == self.tags_count:
for tag in tags: if tag_id:
if tag_id == tag["id"]: for tag in tags:
return Tag( if tag_id == tag["id"]:
id=tag["id"], return Tag(
title=tag["name"] id=tag["id"],
) title=tag["name"]
)
page += 1
kwargs["page"] = page
tags = requests.get(self.base_url + self.tags_url, params={"sort-column": "name", "sort-order": "descending", **kwargs}, headers={"X-API-KEY": self.token}).json()
else:
break
logger.debug(f"{Fore.YELLOW}Получено тегов: {len(tags)}.{Fore.RESET}") logger.debug(f"{Fore.YELLOW}Получено тегов: {len(tags)}.{Fore.RESET}")
return [Tag( return [Tag(
id=tag["id"], id=tag["id"],

View File

@@ -10,7 +10,7 @@ class ClockifyConfig:
self.user_url = "/user" self.user_url = "/user"
self.projects_url = f"{self.workspace_url}/projects" self.projects_url = f"{self.workspace_url}/projects"
self.tags_count = 100 self.tags_count = 20
def update_time_entry(self, activity_id): def update_time_entry(self, activity_id):
return f"{self.workspace_url}/time-entries/{activity_id}" return f"{self.workspace_url}/time-entries/{activity_id}"