Merge pull request 'Изменил отображение в консоли и проработал режим отладки' (#15) from dev into master
Reviewed-on: #15
This commit was merged in pull request #15.
This commit is contained in:
@@ -140,6 +140,7 @@ class ClockifyAPI(ClockifyConfig):
|
||||
"""
|
||||
for activity in activities:
|
||||
try:
|
||||
if not config.is_debug:
|
||||
resp = requests.put(
|
||||
self.base_url + self.update_time_entry(
|
||||
activity_id=activity.id
|
||||
@@ -155,12 +156,11 @@ class ClockifyAPI(ClockifyConfig):
|
||||
"X-API-KEY": self.token
|
||||
}
|
||||
)
|
||||
if resp.ok:
|
||||
logger.debug(resp.json())
|
||||
logger.info(f"✅{Fore.GREEN}{activity}{Fore.RESET}")
|
||||
if config.is_debug or resp.ok:
|
||||
logger.info(f"{Fore.GREEN}{activity}{Fore.RESET}".ljust(60) + "✅")
|
||||
else:
|
||||
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:
|
||||
logger.error(e)
|
||||
return
|
||||
|
||||
@@ -37,6 +37,7 @@ class RedmineAPI(RedmineConfig):
|
||||
if not(not activity.is_tracked and activity.date_end):
|
||||
continue
|
||||
try:
|
||||
if not config.is_debug:
|
||||
resp = requests.post(
|
||||
self.base_url + self.time_entries_url,
|
||||
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
|
||||
tracked.append(activity)
|
||||
logger.debug(activity)
|
||||
|
||||
@@ -19,7 +19,7 @@ class Activity:
|
||||
is_tracked: bool = False
|
||||
|
||||
def __str__(self):
|
||||
return f'({self.task_id}) - {self.description};'
|
||||
return f'({self.task_id}) - {self.description}'[:60]
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -17,6 +17,8 @@ class Config(BaseSettings):
|
||||
USER_ID: str = None
|
||||
WORKSPACE_ID: str = None
|
||||
|
||||
MODE: str = "prod"
|
||||
|
||||
TRIAL_END_DATE: str = datetime.today().strftime("%Y-%m-%d")
|
||||
|
||||
ENV_TXT: str = ".env.txt"
|
||||
@@ -45,6 +47,10 @@ class Config(BaseSettings):
|
||||
from utils import str_to_date
|
||||
return datetime.today() < str_to_date(self.TRIAL_END_DATE)
|
||||
|
||||
@property
|
||||
def is_debug(self):
|
||||
return self.MODE == "debug"
|
||||
|
||||
|
||||
def configure_argument_parser():
|
||||
parser = argparse.ArgumentParser(description='Трекер трудочасов с Clockify в Redmine')
|
||||
|
||||
11
track.py
11
track.py
@@ -3,7 +3,7 @@ import sys
|
||||
|
||||
logging.basicConfig(
|
||||
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=[
|
||||
logging.FileHandler('app.log', encoding='utf-8'),
|
||||
logging.StreamHandler(sys.stdout)
|
||||
@@ -13,14 +13,15 @@ logging.basicConfig(
|
||||
|
||||
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
|
||||
|
||||
|
||||
def main():
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
if args.debug:
|
||||
if is_debug := args.debug:
|
||||
config.MODE = "debug"
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -59,12 +60,10 @@ def main():
|
||||
logger.info(Fore.YELLOW + "Нет задач для занесения трудочасов" + Fore.RESET)
|
||||
return
|
||||
db.insert_activities(activities)
|
||||
if args.debug:
|
||||
logger.debug("Пропускаем этап загрузки трудочасов")
|
||||
return
|
||||
try:
|
||||
tracked_activities = red.track_activities(activities)
|
||||
clock.mark_tracked(tracked_activities)
|
||||
if not is_debug:
|
||||
db.insert_time_entries(tracked_activities)
|
||||
db.insert_activities(tracked_activities)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user