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

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]
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:
db.insert_tags([tag] if isinstance(tag, Tag) else tag)
from config import red
@@ -104,16 +104,25 @@ class ClockifyAPI(ClockifyConfig):
name: str - optional
archived: bool - optional
page-size: int - optional
page: int - optional
"""
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()
if tag_id:
for tag in tags:
if tag_id == tag["id"]:
return Tag(
id=tag["id"],
title=tag["name"]
)
while len(tags) == self.tags_count:
if tag_id:
for tag in tags:
if tag_id == tag["id"]:
return Tag(
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}")
return [Tag(
id=tag["id"],

View File

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