From eb69a29486fec82108d57db0916be0ec0e0760a2 Mon Sep 17 00:00:00 2001 From: Eduard Date: Thu, 22 May 2025 16:57:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=88=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D1=83=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0.=20=D0=92=D1=8B=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=D0=BB=20=D0=B2=D0=B0=D0=B6=D0=BD=D1=8B=D0=B5?= =?UTF-8?q?=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D0=BC=D0=B8=20=D1=86=D0=B2=D0=B5?= =?UTF-8?q?=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/clockify.py | 8 +++----- api/redmine.py | 3 ++- classes/classes.py | 4 +--- db/db.py | 20 ++++++++++---------- track.py | 16 +++++++++++----- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/api/clockify.py b/api/clockify.py index 499d3b5..56b2b6b 100644 --- a/api/clockify.py +++ b/api/clockify.py @@ -42,7 +42,7 @@ class ClockifyAPI(ClockifyConfig): time_worked_out_total += time_to_hour((end if end else datetime.utcnow()) - start) tag = [tag for tag in self.get_tags() if tag.id == tag_id][0] try: - task_id, task_title = tag.title.split(" - ") + task_id, _ = tag.title.split(" - ") except ValueError: logger.info(f'{activity["timeInterval"]["start"]}: {activity["description"]} - Неправильный формат тега {tag}') continue @@ -51,10 +51,8 @@ class ClockifyAPI(ClockifyConfig): id=activity["id"], tag_id=tag_id, task_id=task_id, - task_title=task_title, project_id=activity["projectId"], vetro_project_id=activity["taskId"], - vetro_project_title=config.VETRO_PROJECTS.get(activity.get("taskId")), description=activity["description"], time_spent=time_to_hour((end if end else datetime.utcnow()) - start), date_start=start, @@ -109,10 +107,10 @@ class ClockifyAPI(ClockifyConfig): ) if resp.ok: logger.debug(resp.json()) - logger.info(f"{activity} {Fore.GREEN} помечена как затреканная{Fore.RESET}") + logger.info(f"{Fore.GREEN} {activity} помечена как затреканная{Fore.RESET}") else: logger.debug(resp.json()) - logger.error(f"{activity} {Fore.RED} не помечена как затреканная{Fore.RESET}") + logger.error(f"{Fore.RED} {activity} не помечена как затреканная{Fore.RESET}") except Exception as e: logger.error(e) return diff --git a/api/redmine.py b/api/redmine.py index 5271713..fee8a21 100644 --- a/api/redmine.py +++ b/api/redmine.py @@ -1,5 +1,6 @@ import logging +from colorama import Fore import requests from tqdm import tqdm @@ -46,7 +47,7 @@ class RedmineAPI(RedmineConfig): tracked.append(activity) logger.debug(activity) else: - logger.error(f"{activity} Не была затрекана") + logger.error(Fore.RED + f"{activity} Не была затрекана" + Fore.RED) logger.error(f"{resp.json()['errors']} {resp.status_code}") except Exception as e: logger.error(e) diff --git a/classes/classes.py b/classes/classes.py index cbe1a7c..82dcc76 100644 --- a/classes/classes.py +++ b/classes/classes.py @@ -8,9 +8,7 @@ from enums import ClockifyProjects, VetroProjects class Activity: id: str vetro_project_id: VetroProjects - vetro_project_title: str task_id: int - task_title: str tag_id: str description: str project_id: ClockifyProjects @@ -20,7 +18,7 @@ class Activity: is_tracked: bool = False def __str__(self): - return f'{self.date_start + timedelta(hours=3)}|{self.vetro_project_title}|{self.description} для задачи "{self.task_title}"' + return f'{self.date_start + timedelta(hours=3)}|{self.description} для задачи #{self.task_id}' @dataclass diff --git a/db/db.py b/db/db.py index a22aee8..0d865d8 100644 --- a/db/db.py +++ b/db/db.py @@ -48,8 +48,8 @@ class Database: ) ) self.con.commit() - except Exception as e: - logger.debug(e) + except Exception: + pass if not is_updated: logging.info("База данных устарела. Рекомендуем обновить с помощью флага -i [--init-db]") @@ -72,8 +72,8 @@ class Database: ) ) self.con.commit() - except Exception as e: - logger.debug(e) + except Exception: + pass def insert_tags(self, tags: list[Tag]): @@ -82,8 +82,8 @@ class Database: try: cur.execute("INSERT INTO tags VALUES(?, ?)",(tag.id,tag.title)) self.con.commit() - except Exception as e: - logger.debug(e) + except Exception: + pass def insert_vetro_projects(self, vetro_projects: list[VetroProject]): @@ -92,8 +92,8 @@ class Database: try: cur.execute("INSERT INTO vetro_projects VALUES(?, ?)", (vetro_project.id, vetro_project.title)) self.con.commit() - except Exception as e: - logger.debug(e) + except Exception: + pass def insert_activity_types(self, activity_types: list[ActivityType]): cur = self.con.cursor() @@ -101,5 +101,5 @@ class Database: try: cur.execute("INSERT INTO activity_types VALUES(?, ?)", (activity_type.id, activity_type.title)) self.con.commit() - except Exception as e: - logger.debug(e) + except Exception: + pass diff --git a/track.py b/track.py index 92ab2f4..854e13c 100644 --- a/track.py +++ b/track.py @@ -11,6 +11,8 @@ logging.basicConfig( ) +from colorama import Fore # noqa: E402 + from api import ClockifyAPI, RedmineAPI # noqa: E402 from config import arg_parser, config, db # noqa: E402 from utils import format_date, str_to_date, today_start, today_end # noqa: E402 @@ -48,10 +50,15 @@ def main(): red = RedmineAPI(config.REDMINE_TOKEN) if args.init_db: - logger.info("Обновление базы данных...") - db.insert_tags(clock.get_tags()) - db.insert_vetro_projects(clock.get_vetro_projects()) - db.insert_activity_types(red.get_time_entry_activities()) + logger.info(Fore.YELLOW + "Обновление базы данных..." + Fore.RESET) + try: + db.insert_tags(clock.get_tags()) + db.insert_vetro_projects(clock.get_vetro_projects()) + db.insert_activity_types(red.get_time_entry_activities()) + except Exception as e: + logger.error(Fore.RED + f"Ошибка при обновлении базы данных: {e}" + Fore.RESET) + else: + logger.info(Fore.GREEN + "База данных теперь актуальна." + Fore.RESET) activities = clock.get_activities( **{ @@ -71,6 +78,5 @@ def main(): except Exception as e: logger.error(e) - if __name__ == "__main__": main()