habitmove/loop/repetitions.py

36 lines
1.1 KiB
Python
Raw Normal View History

2021-08-28 21:03:12 +00:00
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:
2021-08-28 21:03:12 +00:00
c.execute("select id from Habits where uuid = ?", [(habit["uuid"])])
id = c.fetchone()[0]
print(f"register: {habit['name']} in {text} at {event['end']}")
2021-08-28 21:03:12 +00:00
try:
add_repetition(c, id, event["end"])
except sqlite3.IntegrityError:
print("fail to register: not unique")
2021-08-28 21:03:12 +00:00
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),
)