Исправил некоторые поля в базе
This commit is contained in:
@@ -31,7 +31,7 @@ class ClockifyAPI(ClockifyConfig):
|
|||||||
result = []
|
result = []
|
||||||
for activity in tqdm(activities, desc="Парсинг задач"):
|
for activity in tqdm(activities, desc="Парсинг задач"):
|
||||||
if not activity.get("tagIds"):
|
if not activity.get("tagIds"):
|
||||||
logging.info(f"{activity["timeInterval"]["start"]}: {activity["description"]} - У задачи нет тегов")
|
logging.info(f'{activity["timeInterval"]["start"]}: {activity["description"]} - У задачи нет тегов')
|
||||||
continue
|
continue
|
||||||
for tag_id in activity.get("tagIds", {"tagIds": []}):
|
for tag_id in activity.get("tagIds", {"tagIds": []}):
|
||||||
start = datetime.strptime(activity["timeInterval"]["start"], config.DATETIME_FORMAT)
|
start = datetime.strptime(activity["timeInterval"]["start"], config.DATETIME_FORMAT)
|
||||||
@@ -41,7 +41,7 @@ class ClockifyAPI(ClockifyConfig):
|
|||||||
try:
|
try:
|
||||||
task_id, task_title = tag.title.split(" - ")
|
task_id, task_title = tag.title.split(" - ")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logging.info(f"{activity["timeInterval"]["start"]}: {activity["description"]} - Неправильный формат тега {tag}")
|
logging.info(f'{activity["timeInterval"]["start"]}: {activity["description"]} - Неправильный формат тега {tag}')
|
||||||
continue
|
continue
|
||||||
result.append(
|
result.append(
|
||||||
Activity(
|
Activity(
|
||||||
|
|||||||
@@ -61,5 +61,5 @@ class RedmineAPI(RedmineConfig):
|
|||||||
logging.error("Invalid Token for RedmineAPI")
|
logging.error("Invalid Token for RedmineAPI")
|
||||||
raise InvalidToken
|
raise InvalidToken
|
||||||
resp = resp.json()['user']
|
resp = resp.json()['user']
|
||||||
logging.debug({"login": resp["login"], "email": resp["mail"], "full_name": f"{resp["firstname"]} {resp["lastname"]}"})
|
logging.debug({"login": resp["login"], "email": resp["mail"], "full_name": f'{resp["firstname"]} {resp["lastname"]}'})
|
||||||
return token
|
return token
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from db.db import Database
|
from db.db import Database
|
||||||
|
|
||||||
|
|
||||||
from .clockify import ClockifyConfig # noqa: F401
|
from .clockify import ClockifyConfig # noqa: F401
|
||||||
from .redmine import RedmineConfig # noqa: F401
|
from .redmine import RedmineConfig # noqa: F401
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseSettings):
|
class Config(BaseSettings):
|
||||||
CLOCKIFY_TOKEN: str
|
CLOCKIFY_TOKEN: str
|
||||||
|
|||||||
40
db/db.py
40
db/db.py
@@ -10,19 +10,17 @@ class Database:
|
|||||||
self.con = sq.connect(db_name)
|
self.con = sq.connect(db_name)
|
||||||
self.con.cursor().executescript('''CREATE TABLE IF NOT EXISTS "activities" (
|
self.con.cursor().executescript('''CREATE TABLE IF NOT EXISTS "activities" (
|
||||||
"id" VARCHAR NOT NULL UNIQUE,
|
"id" VARCHAR NOT NULL UNIQUE,
|
||||||
"vetro_project_id" VARCHAR NOT NULL,
|
|
||||||
"vetro_project_title" VARCHAR NOT NULL,
|
|
||||||
"task_id" VARCHAR NOT NULL,
|
|
||||||
"description" VARCHAR NOT NULL,
|
"description" VARCHAR NOT NULL,
|
||||||
"task_title" VARCHAR NOT NULL,
|
|
||||||
"tag_id" VARCHAR NOT NULL,
|
|
||||||
"project_id" VARCHAR NOT NULL,
|
|
||||||
"time_spent" NUMERIC NOT NULL,
|
"time_spent" NUMERIC NOT NULL,
|
||||||
"date_start" DATETIME NOT NULL,
|
"date_start" DATETIME NOT NULL,
|
||||||
"date_end" DATETIME,
|
"date_end" DATETIME,
|
||||||
"is_tracked" BOOLEAN NOT NULL DEFAULT false,
|
"is_tracked" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"vetro_project_id" VARCHAR NOT NULL,
|
||||||
|
"tag_id" VARCHAR NOT NULL,
|
||||||
|
"project_id" VARCHAR NOT NULL,
|
||||||
PRIMARY KEY("id"),
|
PRIMARY KEY("id"),
|
||||||
FOREIGN KEY ("tag_id") REFERENCES "tags"("id")
|
FOREIGN KEY ("tag_id") REFERENCES "tags"("id")
|
||||||
|
FOREIGN KEY ("vetro_project_id") REFERENCES "vetro_projects"("id")
|
||||||
ON UPDATE NO ACTION ON DELETE NO ACTION
|
ON UPDATE NO ACTION ON DELETE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -35,9 +33,7 @@ CREATE TABLE IF NOT EXISTS "tags" (
|
|||||||
CREATE TABLE IF NOT EXISTS "vetro_projects" (
|
CREATE TABLE IF NOT EXISTS "vetro_projects" (
|
||||||
"id" VARCHAR NOT NULL UNIQUE,
|
"id" VARCHAR NOT NULL UNIQUE,
|
||||||
"title" VARCHAR NOT NULL,
|
"title" VARCHAR NOT NULL,
|
||||||
PRIMARY KEY("id"),
|
PRIMARY KEY("id")
|
||||||
FOREIGN KEY ("id") REFERENCES "activities"("vetro_project_id")
|
|
||||||
ON UPDATE NO ACTION ON DELETE NO ACTION
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS "time_entry" (
|
CREATE TABLE IF NOT EXISTS "time_entry" (
|
||||||
@@ -63,19 +59,17 @@ CREATE TABLE IF NOT EXISTS "time_entry" (
|
|||||||
for act in activities:
|
for act in activities:
|
||||||
try:
|
try:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"INSERT INTO activities VALUES(?, ?, ? ,? ,? ,? ,? ,? ,? ,? ,? ,?)",
|
"INSERT INTO activities VALUES(?,?,?,?,?,?,?,?,?)",
|
||||||
(
|
(
|
||||||
act.id,act.vetro_project_id,
|
act.id,
|
||||||
act.vetro_project_title,
|
|
||||||
act.task_id,
|
|
||||||
act.description,
|
act.description,
|
||||||
act.task_title,
|
|
||||||
act.tag_id,
|
|
||||||
act.project_id,
|
|
||||||
act.time_spent,
|
act.time_spent,
|
||||||
act.date_start,
|
act.date_start,
|
||||||
act.date_end,
|
act.date_end,
|
||||||
act.is_tracked
|
act.is_tracked,
|
||||||
|
act.vetro_project_id,
|
||||||
|
act.tag_id,
|
||||||
|
act.project_id,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
@@ -124,3 +118,15 @@ CREATE TABLE IF NOT EXISTS "time_entry" (
|
|||||||
logging.error(e)
|
logging.error(e)
|
||||||
|
|
||||||
|
|
||||||
|
def insert_vetro_projects(self, vetro_projects: dict):
|
||||||
|
cur = self.con.cursor()
|
||||||
|
for k, v in vetro_projects.items():
|
||||||
|
try:
|
||||||
|
cur.execute("INSERT INTO vetro_projects VALUES(?, ?)", (k, v))
|
||||||
|
self.con.commit()
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
track.py
2
track.py
@@ -38,6 +38,8 @@ def main():
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
db.insert_activities(activities)
|
db.insert_activities(activities)
|
||||||
|
db.insert_tags(clock.get_tags())
|
||||||
|
db.insert_vetro_projects(config.VETRO_PROJECTS)
|
||||||
# tracked_activities = red.track_activities(activities)
|
# tracked_activities = red.track_activities(activities)
|
||||||
# clock.mark_tracked(tracked_activities)
|
# clock.mark_tracked(tracked_activities)
|
||||||
for activity in activities:
|
for activity in activities:
|
||||||
|
|||||||
Reference in New Issue
Block a user