Skip imported facts, more 4matting

This commit is contained in:
3wc 2023-11-01 19:39:10 +00:00
parent cb909540fa
commit 19e230932f
3 changed files with 23 additions and 4 deletions

View File

@ -88,7 +88,7 @@ class HamsterActivityKimaiMapping(Model):
class HamsterFactKimaiImport(Model):
hamster_fact = ForeignKeyField(HamsterFact, backref="mappings")
hamster_fact = ForeignKeyField(HamsterFact, backref="imports")
kimai_id = SmallIntegerField()
imported = DateTimeField(default=datetime.now)

View File

@ -6,7 +6,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from datetime import datetime, timedelta
import logging
from hamstertools.kimai import *
from hamstertools.kimai import KimaiAPI, Timesheet, Project, Activity
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)

View File

@ -7,8 +7,13 @@ from datetime import datetime
from peewee import JOIN
from hamstertools.db import *
from hamstertools.kimai import *
from hamstertools.db import (
HamsterCategory,
HamsterActivity,
HamsterFact,
HamsterFactKimaiImport,
)
from hamstertools.kimai import KimaiAPI, Timesheet, Project, Activity
api = KimaiAPI()
@ -53,6 +58,13 @@ for f in facts:
)
has_errors = True
continue
if f.imports.count() > 0:
print(
f"fact {f.id}: activity @{f.activity.id} {f.activity.name} was already imported {f.imports.count()} time(s)"
)
has_errors = True
continue
# if has_errors:
# sys.exit(1)
@ -66,6 +78,13 @@ for f in facts:
f"no mapping, skipping {f.id} ({f.activity.category.name} » {f.activity.name})"
)
continue
if f.imports.count() > 0:
print(
f"already imported, skipping {f.id} ({f.activity.category.name} » {f.activity.name})"
)
continue
t = Timesheet(
api,
activity=mapping.kimai_activity,