diff --git a/api/clockify.py b/api/clockify.py index 44e1e9e..e33aa11 100644 --- a/api/clockify.py +++ b/api/clockify.py @@ -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"], diff --git a/config/clockify.py b/config/clockify.py index 663f20d..d0a8880 100644 --- a/config/clockify.py +++ b/config/clockify.py @@ -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}"