Проработал режим отладки
This commit is contained in:
@@ -140,27 +140,27 @@ class ClockifyAPI(ClockifyConfig):
|
|||||||
"""
|
"""
|
||||||
for activity in activities:
|
for activity in activities:
|
||||||
try:
|
try:
|
||||||
resp = requests.put(
|
if not config.is_debug:
|
||||||
self.base_url + self.update_time_entry(
|
resp = requests.put(
|
||||||
activity_id=activity.id
|
self.base_url + self.update_time_entry(
|
||||||
), json={
|
activity_id=activity.id
|
||||||
"billable": True,
|
), json={
|
||||||
"start": activity.date_start.strftime(config.DATETIME_FORMAT),
|
"billable": True,
|
||||||
"end": activity.date_end.strftime(config.DATETIME_FORMAT) if activity.date_end else None,
|
"start": activity.date_start.strftime(config.DATETIME_FORMAT),
|
||||||
"description": activity.description,
|
"end": activity.date_end.strftime(config.DATETIME_FORMAT) if activity.date_end else None,
|
||||||
"tagIds": [activity.tag_id],
|
"description": activity.description,
|
||||||
"taskId": activity.vetro_project_id,
|
"tagIds": [activity.tag_id],
|
||||||
"projectId": activity.project_id
|
"taskId": activity.vetro_project_id,
|
||||||
}, headers={
|
"projectId": activity.project_id
|
||||||
"X-API-KEY": self.token
|
}, headers={
|
||||||
}
|
"X-API-KEY": self.token
|
||||||
)
|
}
|
||||||
if resp.ok:
|
)
|
||||||
logger.debug(resp.json())
|
if config.is_debug or resp.ok:
|
||||||
logger.info(f"✅{Fore.GREEN}{activity}{Fore.RESET}")
|
logger.info(f"{Fore.GREEN}{activity}{Fore.RESET}✅")
|
||||||
else:
|
else:
|
||||||
logger.debug(resp.json())
|
logger.debug(resp.json())
|
||||||
logger.error(f"❌{Fore.RED}{activity}{Fore.RESET}")
|
logger.error(f"{Fore.RED}{activity}{Fore.RESET}❌")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -37,20 +37,21 @@ class RedmineAPI(RedmineConfig):
|
|||||||
if not(not activity.is_tracked and activity.date_end):
|
if not(not activity.is_tracked and activity.date_end):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
resp = requests.post(
|
if not config.is_debug:
|
||||||
self.base_url + self.time_entries_url,
|
resp = requests.post(
|
||||||
headers={"X-Redmine-Api-Key": self.token},
|
self.base_url + self.time_entries_url,
|
||||||
json={
|
headers={"X-Redmine-Api-Key": self.token},
|
||||||
"time_entry": {
|
json={
|
||||||
"issue_id": activity.task_id,
|
"time_entry": {
|
||||||
"hours": activity.time_spent / (2 if is_beginner else 1),
|
"issue_id": activity.task_id,
|
||||||
"activity_id": ActivityTypes.DEVELOPMENT,
|
"hours": activity.time_spent / (2 if is_beginner else 1),
|
||||||
"comments": activity.description,
|
"activity_id": ActivityTypes.DEVELOPMENT,
|
||||||
"spent_on": activity.date_start.strftime(self.datetime_format)
|
"comments": activity.description,
|
||||||
|
"spent_on": activity.date_start.strftime(self.datetime_format)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
if config.is_debug or resp.ok:
|
||||||
if resp.ok:
|
|
||||||
activity.is_tracked = True
|
activity.is_tracked = True
|
||||||
tracked.append(activity)
|
tracked.append(activity)
|
||||||
logger.debug(activity)
|
logger.debug(activity)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class Activity:
|
|||||||
is_tracked: bool = False
|
is_tracked: bool = False
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'({self.task_id}) - {self.description};'
|
return f'({self.task_id}) - {self.description}'[:60]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class Config(BaseSettings):
|
|||||||
USER_ID: str = None
|
USER_ID: str = None
|
||||||
WORKSPACE_ID: str = None
|
WORKSPACE_ID: str = None
|
||||||
|
|
||||||
|
MODE: str = "prod"
|
||||||
|
|
||||||
TRIAL_END_DATE: str = datetime.today().strftime("%Y-%m-%d")
|
TRIAL_END_DATE: str = datetime.today().strftime("%Y-%m-%d")
|
||||||
|
|
||||||
ENV_TXT: str = ".env.txt"
|
ENV_TXT: str = ".env.txt"
|
||||||
@@ -44,6 +46,10 @@ class Config(BaseSettings):
|
|||||||
def is_beginner(self):
|
def is_beginner(self):
|
||||||
from utils import str_to_date
|
from utils import str_to_date
|
||||||
return datetime.today() < str_to_date(self.TRIAL_END_DATE)
|
return datetime.today() < str_to_date(self.TRIAL_END_DATE)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_debug(self):
|
||||||
|
return self.MODE == "debug"
|
||||||
|
|
||||||
|
|
||||||
def configure_argument_parser():
|
def configure_argument_parser():
|
||||||
|
|||||||
15
track.py
15
track.py
@@ -13,14 +13,15 @@ logging.basicConfig(
|
|||||||
|
|
||||||
from colorama import Fore # noqa: E402
|
from colorama import Fore # noqa: E402
|
||||||
|
|
||||||
from config import arg_parser, clock, db, red # noqa: E402
|
from config import arg_parser, clock, config, db, red # noqa: E402
|
||||||
from utils import check_envs, db_update, format_date, get_start_end_dates # noqa: E402
|
from utils import check_envs, db_update, format_date, get_start_end_dates # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = arg_parser.parse_args()
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
if args.debug:
|
if is_debug := args.debug:
|
||||||
|
config.MODE = "debug"
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
logging.getLogger().setLevel(logging.DEBUG)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -59,14 +60,12 @@ def main():
|
|||||||
logger.info(Fore.YELLOW + "Нет задач для занесения трудочасов" + Fore.RESET)
|
logger.info(Fore.YELLOW + "Нет задач для занесения трудочасов" + Fore.RESET)
|
||||||
return
|
return
|
||||||
db.insert_activities(activities)
|
db.insert_activities(activities)
|
||||||
if args.debug:
|
|
||||||
logger.debug("Пропускаем этап загрузки трудочасов")
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
tracked_activities = red.track_activities(activities)
|
tracked_activities = red.track_activities(activities)
|
||||||
clock.mark_tracked(tracked_activities)
|
clock.mark_tracked(tracked_activities)
|
||||||
db.insert_time_entries(tracked_activities)
|
if not is_debug:
|
||||||
db.insert_activities(tracked_activities)
|
db.insert_time_entries(tracked_activities)
|
||||||
|
db.insert_activities(tracked_activities)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user