Add repetition import

This commit is contained in:
Marty Oehme 2021-08-28 23:03:12 +02:00
parent 76fcae499a
commit 3c081f745c
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
4 changed files with 44 additions and 46 deletions

View File

@ -8,6 +8,8 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe
## [Unreleased]
* Add range habits, translating nomie max value to range target in Loop
* Add repetition import, translated from events
* Does not do ranged habits or multiple entries for simple trackers in nomie yet
## [0.2.1] - 2021-08-28

View File

@ -7,6 +7,7 @@ def migrate(db, trackers):
add_to_database(c, habit)
else:
print(f"Found duplicate Habit: {existing_habit} - skipping.")
return habits
def trackers_to_habits(trackers):
@ -17,7 +18,7 @@ def trackers_to_habits(trackers):
{
"archived": 0 if t["hidden"] == False else 1,
"color": 11 if t.get("score", 0) != "-1" else 0,
"description": t["label"],
"description": t["tag"],
"freq_den": 1,
"freq_num": 1,
"highlight": 0,
@ -50,47 +51,3 @@ def add_to_database(cursor, habit_dict):
)
values = list(habit_dict.values())
cursor.execute(sql, values)
# grab next tracker info
# look for unique id of next habit
# if exists skip and warn user
# insert tracker into habit table
# FOR REPETITION MIGRATION
# c.execute(
# """
# INSERT INTO
# Repetitions(id, habit, timestamp, value)
# VALUES (NULL, 5, 1629676800000, 2)
# """
# )
# c.execute(
# """
# INSERT INTO
# Repetitions(id, habit, timestamp, value)
# VALUES (NULL, 6, 1629676800000, 2)
# """
# )
# """
# )
# """
# )
# """
# )
# """
# )
# """
# )
# """
# )
# """
# )
# """
# )
# """
# )
# """
# )

View File

@ -1,10 +1,16 @@
import loop.tables as tables
import loop.habits as habits
import loop.repetitions as rep
def migrate(trackers, events):
db = tables.migrate("output.db")
if trackers is not None:
habits.migrate(db, trackers)
habitlist = habits.migrate(db, trackers)
if events is not None:
rep.migrate(db, habitlist, events)
db.commit()
db.close()

33
loop/repetitions.py Normal file
View File

@ -0,0 +1,33 @@
import sqlite3
def migrate(db, habitlist, events):
c = db.cursor()
for event in events:
text = event["note"]
for habit in habitlist:
if f"#{habit['description']}" in text:
c.execute("select id from Habits where uuid = ?", [(habit["uuid"])])
id = c.fetchone()[0]
print(f"found: {habit['name']} in {text}")
try:
add_repetition(c, id, event["end"])
except sqlite3.IntegrityError:
pass
# does not do:
# ranges in habits (should check for habit being range, then taking #habit(3) number into account)
# also, range trackers: multiply value by 1,000
# non-range habits but still #habit(3) number included, adding multiple?
def add_repetition(cursor, habit_id, timestamp, value=2):
cursor.execute(
"""
INSERT INTO
Repetitions(id, habit, timestamp, value)
VALUES (NULL, ?, ?, ?)
""",
(habit_id, timestamp, value),
)