0
This commit is contained in:
23
api.py
23
api.py
@@ -1,4 +1,4 @@
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -15,18 +15,6 @@ WORKSPACE_ID = config.CLOCKIFY_WORKSPACE_ID
|
|||||||
USER_ID = config.CLOCKIFY_USER_ID
|
USER_ID = config.CLOCKIFY_USER_ID
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
{
|
|
||||||
"time_entry": {
|
|
||||||
"issue_id": 28882,
|
|
||||||
"hours": 0.55,
|
|
||||||
"activity_id": 9,
|
|
||||||
"comments": "Дейлик"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class ClockifyAPI(ClockifyConfig):
|
class ClockifyAPI(ClockifyConfig):
|
||||||
def __init__(self, token: str):
|
def __init__(self, token: str):
|
||||||
self.token = self._check_token(token)
|
self.token = self._check_token(token)
|
||||||
@@ -46,8 +34,8 @@ class ClockifyAPI(ClockifyConfig):
|
|||||||
result = []
|
result = []
|
||||||
for activity in tqdm(activities, desc="Парсинг задач"):
|
for activity in tqdm(activities, desc="Парсинг задач"):
|
||||||
for tag_id in activity["tagIds"]:
|
for tag_id in activity["tagIds"]:
|
||||||
start = datetime.strptime(activity["timeInterval"]["start"], config.DATETIME_FORMAT)
|
start = datetime.strptime(activity["timeInterval"]["start"], config.DATETIME_FORMAT) + timedelta(hours=3)
|
||||||
end = datetime.strptime(activity["timeInterval"]["end"] or str(datetime.now(timezone.utc).strftime(config.DATETIME_FORMAT)), config.DATETIME_FORMAT)
|
end = datetime.strptime(activity["timeInterval"]["end"] or str(datetime.now(timezone.utc).strftime(config.DATETIME_FORMAT)), config.DATETIME_FORMAT) + timedelta(hours=3)
|
||||||
time_worked_out_total += time_to_hour(end - start)
|
time_worked_out_total += time_to_hour(end - start)
|
||||||
tag = [tag for tag in self.get_tags(workspace_id=WORKSPACE_ID) if tag.id == tag_id][0]
|
tag = [tag for tag in self.get_tags(workspace_id=WORKSPACE_ID) if tag.id == tag_id][0]
|
||||||
task_id, task_title = tag.title.split(" - ")
|
task_id, task_title = tag.title.split(" - ")
|
||||||
@@ -58,7 +46,8 @@ class ClockifyAPI(ClockifyConfig):
|
|||||||
task_title=task_title,
|
task_title=task_title,
|
||||||
description=activity["description"],
|
description=activity["description"],
|
||||||
time_spent=time_to_hour(end - start),
|
time_spent=time_to_hour(end - start),
|
||||||
date=end
|
date_start=start,
|
||||||
|
date_end=end
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
logging.info(f"Сохранено задач: {len(result)}")
|
logging.info(f"Сохранено задач: {len(result)}")
|
||||||
@@ -98,7 +87,7 @@ class ClockifyAPI(ClockifyConfig):
|
|||||||
|
|
||||||
|
|
||||||
def _check_token(self, token: str) -> str:
|
def _check_token(self, token: str) -> str:
|
||||||
resp = requests.get(self.base_url + self.config.user_url, headers={"X-API-KEY": token})
|
resp = requests.get(self.base_url + self.user_url, headers={"X-API-KEY": token})
|
||||||
if not resp.ok:
|
if not resp.ok:
|
||||||
logging.error(resp.json())
|
logging.error(resp.json())
|
||||||
raise InvalidToken
|
raise InvalidToken
|
||||||
|
|||||||
@@ -9,14 +9,15 @@ class Activity:
|
|||||||
task_title: str
|
task_title: str
|
||||||
description: str
|
description: str
|
||||||
time_spent: float
|
time_spent: float
|
||||||
date: datetime = datetime.now()
|
date_start: datetime
|
||||||
|
date_end: datetime
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_tracked(self):
|
def is_tracked(self):
|
||||||
return self.description.startswith("*")
|
return self.description.startswith("*")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.date}: {self.description.strip("*")} для задачи "{self.task_title}"'
|
return f'{self.date_start}: {self.description.strip("*")} для задачи "{self.task_title}"'
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
13
main.py
13
main.py
@@ -9,14 +9,11 @@ from utils import today_start, today_end
|
|||||||
def main():
|
def main():
|
||||||
clock = ClockifyAPI(config.CLOCKIFY_TOKEN)
|
clock = ClockifyAPI(config.CLOCKIFY_TOKEN)
|
||||||
red = RedmineAPI(config.REDMINE_TOKEN)
|
red = RedmineAPI(config.REDMINE_TOKEN)
|
||||||
if False:
|
tracked_activities = red.track_activities(clock.get_activities(
|
||||||
tracked_activities = red.track_activities(clock.get_activities(
|
start=today_start(),
|
||||||
start=today_start(),
|
end=today_end()
|
||||||
end=today_end()
|
))
|
||||||
))
|
clock.mark_tracked(tracked_activities)
|
||||||
clock.mark_tracked(tracked_activities)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user