64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
import logging
|
|
import sys
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s %(name)s:%(lineno)d %(levelname)s %(message)s',
|
|
handlers=[
|
|
logging.FileHandler('app.log', encoding='utf-8'),
|
|
logging.StreamHandler(sys.stdout)
|
|
]
|
|
)
|
|
|
|
|
|
from api.clockify import ClockifyAPI # noqa: E402
|
|
from api.redmine import RedmineAPI # noqa: E402
|
|
from config import arg_parser, config # noqa: E402
|
|
from db.db import Database # noqa: E402
|
|
from services.tracking import TrackingService # noqa: E402
|
|
from utils import check_envs, db_update, get_start_end_dates # noqa: E402
|
|
|
|
|
|
def main():
|
|
"""Запускает CLI-сценарий переноса трудочасов из Clockify в Redmine."""
|
|
args = arg_parser.parse_args()
|
|
|
|
if is_debug := args.debug:
|
|
config.MODE = "debug"
|
|
logging.getLogger().setLevel(logging.DEBUG)
|
|
if is_dry_run := args.dry_run:
|
|
config.MODE = "debug"
|
|
|
|
logger = logging.getLogger(__name__)
|
|
db = Database(config.DB_NAME, config.SQL_PATH)
|
|
red = RedmineAPI(config.REDMINE_TOKEN)
|
|
clock = ClockifyAPI(
|
|
token=config.CLOCKIFY_TOKEN,
|
|
workspace_id=config.WORKSPACE_ID,
|
|
user_id=config.USER_ID,
|
|
db=db,
|
|
redmine_api=red,
|
|
)
|
|
|
|
start, end = get_start_end_dates(args)
|
|
|
|
if not check_envs(clock):
|
|
return
|
|
|
|
if args.init_db:
|
|
db_update(clock, db, red)
|
|
|
|
try:
|
|
TrackingService(
|
|
clock=clock,
|
|
red=red,
|
|
db=db,
|
|
is_debug=is_debug,
|
|
is_dry_run=is_dry_run,
|
|
).track_period(start=start, end=end, page_size=args.page_size)
|
|
except Exception as e:
|
|
logger.error(e)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|