Изменил отображение в консоли и проработал режим отладки #15
@@ -140,6 +140,7 @@ class ClockifyAPI(ClockifyConfig):
|
|||||||
"""
|
"""
|
||||||
for activity in activities:
|
for activity in activities:
|
||||||
try:
|
try:
|
||||||
|
if not config.is_debug:
|
||||||
resp = requests.put(
|
resp = requests.put(
|
||||||
self.base_url + self.update_time_entry(
|
self.base_url + self.update_time_entry(
|
||||||
activity_id=activity.id
|
activity_id=activity.id
|
||||||
@@ -155,12 +156,11 @@ class ClockifyAPI(ClockifyConfig):
|
|||||||
"X-API-KEY": self.token
|
"X-API-KEY": self.token
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if resp.ok:
|
if config.is_debug or resp.ok:
|
||||||
logger.debug(resp.json())
|
logger.info(f"{Fore.GREEN}{activity}{Fore.RESET}".ljust(60) + "✅")
|
||||||
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}".ljust(60) + "❌")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ 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:
|
||||||
|
if not config.is_debug:
|
||||||
resp = requests.post(
|
resp = requests.post(
|
||||||
self.base_url + self.time_entries_url,
|
self.base_url + self.time_entries_url,
|
||||||
headers={"X-Redmine-Api-Key": self.token},
|
headers={"X-Redmine-Api-Key": self.token},
|
||||||
@@ -50,7 +51,7 @@ class RedmineAPI(RedmineConfig):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if resp.ok:
|
if config.is_debug or 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"
|
||||||
@@ -45,6 +47,10 @@ class Config(BaseSettings):
|
|||||||
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():
|
||||||
parser = argparse.ArgumentParser(description='Трекер трудочасов с Clockify в Redmine')
|
parser = argparse.ArgumentParser(description='Трекер трудочасов с Clockify в Redmine')
|
||||||
|
|||||||
11
track.py
11
track.py
@@ -3,7 +3,7 @@ import sys
|
|||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format='%(asctime)s - %(name)s:%(lineno)d - %(levelname)s - %(message)s',
|
format='%(asctime)s %(name)s:%(lineno)d %(levelname)s %(message)s',
|
||||||
handlers=[
|
handlers=[
|
||||||
logging.FileHandler('app.log', encoding='utf-8'),
|
logging.FileHandler('app.log', encoding='utf-8'),
|
||||||
logging.StreamHandler(sys.stdout)
|
logging.StreamHandler(sys.stdout)
|
||||||
@@ -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,12 +60,10 @@ 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)
|
||||||
|
if not is_debug:
|
||||||
db.insert_time_entries(tracked_activities)
|
db.insert_time_entries(tracked_activities)
|
||||||
db.insert_activities(tracked_activities)
|
db.insert_activities(tracked_activities)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user