Исправил некоторые поля в базе
This commit is contained in:
@@ -31,7 +31,7 @@ class ClockifyAPI(ClockifyConfig):
|
||||
result = []
|
||||
for activity in tqdm(activities, desc="Парсинг задач"):
|
||||
if not activity.get("tagIds"):
|
||||
logging.info(f"{activity["timeInterval"]["start"]}: {activity["description"]} - У задачи нет тегов")
|
||||
logging.info(f'{activity["timeInterval"]["start"]}: {activity["description"]} - У задачи нет тегов')
|
||||
continue
|
||||
for tag_id in activity.get("tagIds", {"tagIds": []}):
|
||||
start = datetime.strptime(activity["timeInterval"]["start"], config.DATETIME_FORMAT)
|
||||
@@ -41,7 +41,7 @@ class ClockifyAPI(ClockifyConfig):
|
||||
try:
|
||||
task_id, task_title = tag.title.split(" - ")
|
||||
except ValueError:
|
||||
logging.info(f"{activity["timeInterval"]["start"]}: {activity["description"]} - Неправильный формат тега {tag}")
|
||||
logging.info(f'{activity["timeInterval"]["start"]}: {activity["description"]} - Неправильный формат тега {tag}')
|
||||
continue
|
||||
result.append(
|
||||
Activity(
|
||||
|
||||
@@ -61,5 +61,5 @@ class RedmineAPI(RedmineConfig):
|
||||
logging.error("Invalid Token for RedmineAPI")
|
||||
raise InvalidToken
|
||||
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
|
||||
@@ -1,12 +1,14 @@
|
||||
import argparse
|
||||
from pydantic_settings import BaseSettings
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from db.db import Database
|
||||
|
||||
|
||||
from .clockify import ClockifyConfig # noqa: F401
|
||||
from .redmine import RedmineConfig # noqa: F401
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
class Config(BaseSettings):
|
||||
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.cursor().executescript('''CREATE TABLE IF NOT EXISTS "activities" (
|
||||
"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,
|
||||
"task_title" VARCHAR NOT NULL,
|
||||
"tag_id" VARCHAR NOT NULL,
|
||||
"project_id" VARCHAR NOT NULL,
|
||||
"time_spent" NUMERIC NOT NULL,
|
||||
"date_start" DATETIME NOT NULL,
|
||||
"date_end" DATETIME,
|
||||
"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"),
|
||||
FOREIGN KEY ("tag_id") REFERENCES "tags"("id")
|
||||
FOREIGN KEY ("vetro_project_id") REFERENCES "vetro_projects"("id")
|
||||
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" (
|
||||
"id" VARCHAR NOT NULL UNIQUE,
|
||||
"title" VARCHAR NOT NULL,
|
||||
PRIMARY KEY("id"),
|
||||
FOREIGN KEY ("id") REFERENCES "activities"("vetro_project_id")
|
||||
ON UPDATE NO ACTION ON DELETE NO ACTION
|
||||
PRIMARY KEY("id")
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "time_entry" (
|
||||
@@ -63,19 +59,17 @@ CREATE TABLE IF NOT EXISTS "time_entry" (
|
||||
for act in activities:
|
||||
try:
|
||||
cur.execute(
|
||||
"INSERT INTO activities VALUES(?, ?, ? ,? ,? ,? ,? ,? ,? ,? ,? ,?)",
|
||||
"INSERT INTO activities VALUES(?,?,?,?,?,?,?,?,?)",
|
||||
(
|
||||
act.id,act.vetro_project_id,
|
||||
act.vetro_project_title,
|
||||
act.task_id,
|
||||
act.id,
|
||||
act.description,
|
||||
act.task_title,
|
||||
act.tag_id,
|
||||
act.project_id,
|
||||
act.time_spent,
|
||||
act.date_start,
|
||||
act.date_end,
|
||||
act.is_tracked
|
||||
act.is_tracked,
|
||||
act.vetro_project_id,
|
||||
act.tag_id,
|
||||
act.project_id,
|
||||
)
|
||||
)
|
||||
self.con.commit()
|
||||
@@ -124,3 +118,15 @@ CREATE TABLE IF NOT EXISTS "time_entry" (
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user