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 requests
|
||||
@@ -15,18 +15,6 @@ WORKSPACE_ID = config.CLOCKIFY_WORKSPACE_ID
|
||||
USER_ID = config.CLOCKIFY_USER_ID
|
||||
|
||||
|
||||
"""
|
||||
{
|
||||
"time_entry": {
|
||||
"issue_id": 28882,
|
||||
"hours": 0.55,
|
||||
"activity_id": 9,
|
||||
"comments": "Дейлик"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
class ClockifyAPI(ClockifyConfig):
|
||||
def __init__(self, token: str):
|
||||
self.token = self._check_token(token)
|
||||
@@ -46,8 +34,8 @@ class ClockifyAPI(ClockifyConfig):
|
||||
result = []
|
||||
for activity in tqdm(activities, desc="Парсинг задач"):
|
||||
for tag_id in activity["tagIds"]:
|
||||
start = datetime.strptime(activity["timeInterval"]["start"], config.DATETIME_FORMAT)
|
||||
end = datetime.strptime(activity["timeInterval"]["end"] or str(datetime.now(timezone.utc).strftime(config.DATETIME_FORMAT)), 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) + timedelta(hours=3)
|
||||
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]
|
||||
task_id, task_title = tag.title.split(" - ")
|
||||
@@ -58,7 +46,8 @@ class ClockifyAPI(ClockifyConfig):
|
||||
task_title=task_title,
|
||||
description=activity["description"],
|
||||
time_spent=time_to_hour(end - start),
|
||||
date=end
|
||||
date_start=start,
|
||||
date_end=end
|
||||
)
|
||||
)
|
||||
logging.info(f"Сохранено задач: {len(result)}")
|
||||
@@ -98,7 +87,7 @@ class ClockifyAPI(ClockifyConfig):
|
||||
|
||||
|
||||
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:
|
||||
logging.error(resp.json())
|
||||
raise InvalidToken
|
||||
|
||||
Reference in New Issue
Block a user