33 lines
1 KiB
Python
33 lines
1 KiB
Python
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),
|
|
)
|