habitmove/loop/repetitions.py

35 lines
1.1 KiB
Python

import sqlite3
def migrate(db, habitlist, events):
c = db.cursor()
for event in events:
text = event["note"]
for habit in habitlist:
tag = f"#{habit['description']}"
if tag in text:
c.execute("select id from Habits where uuid = ?", [(habit["uuid"])])
id = c.fetchone()[0]
print(f"register: {habit['name']} in {text} at {event['end']}")
try:
add_repetition(c, id, event["end"])
except sqlite3.IntegrityError:
print("fail to register: not unique")
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),
)