0
This commit is contained in:
33
api.py
33
api.py
@@ -53,6 +53,7 @@ class ClockifyAPI(ClockifyConfig):
|
||||
task_id, task_title = tag.title.split(" - ")
|
||||
result.append(
|
||||
Activity(
|
||||
id=activity["id"],
|
||||
task_id=task_id,
|
||||
task_title=task_title,
|
||||
description=activity["description"],
|
||||
@@ -77,6 +78,25 @@ class ClockifyAPI(ClockifyConfig):
|
||||
title=tag["name"]
|
||||
) for tag in tags]
|
||||
|
||||
def mark_tracked(self, activities: list[Activity]):
|
||||
for activity in activities:
|
||||
try:
|
||||
resp = requests.put(self.base_url + self.update_time_entry.format(
|
||||
workspace_id=WORKSPACE_ID,
|
||||
id=activity.id
|
||||
), data={
|
||||
"description": "*" + activity.description
|
||||
})
|
||||
if resp.ok:
|
||||
logging.debug(activity, "помечена как затреканная")
|
||||
else:
|
||||
logging.error(activity, "не помечена как затреканная")
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
return
|
||||
|
||||
|
||||
|
||||
def _check_token(self, token: str) -> str:
|
||||
resp = requests.get(self.base_url + self.config.user_url, headers={"X-API-KEY": token})
|
||||
if not resp.ok:
|
||||
@@ -91,11 +111,11 @@ class RedmineAPI(RedmineConfig):
|
||||
def __init__(self, token):
|
||||
self.token = self._check_token(token)
|
||||
|
||||
def track_activities(self, activities: list[Activity]):
|
||||
def track_activities(self, activities: list[Activity]) -> list[Activity]:
|
||||
if len(activities) == 0:
|
||||
logging.info("Нет задач для занесения трудочасов")
|
||||
return
|
||||
tracked = 0
|
||||
tracked = []
|
||||
for activity in tqdm(activities, desc="Занесение трудочасов"):
|
||||
if not activity.is_tracked:
|
||||
try:
|
||||
@@ -114,7 +134,7 @@ class RedmineAPI(RedmineConfig):
|
||||
)
|
||||
if resp.ok:
|
||||
activity.is_tracked = True
|
||||
tracked += 1
|
||||
tracked.append(activity)
|
||||
logging.debug(activity)
|
||||
else:
|
||||
logging.error(activity, "Не была затрекана")
|
||||
@@ -122,8 +142,11 @@ class RedmineAPI(RedmineConfig):
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
continue
|
||||
if len(activities) == tracked:
|
||||
logging.info(f"Все задачи были успешно занесены в Redmine: {tracked}")
|
||||
if len(activities) == len(tracked):
|
||||
logging.info("Все задачи были успешно занесены в Redmine")
|
||||
else:
|
||||
logging.info(f"Не все задачи были занесены в Redmine. Занесено {len(tracked)}")
|
||||
return tracked
|
||||
|
||||
|
||||
def _check_token(self, token):
|
||||
|
||||
Reference in New Issue
Block a user