Rename loop import modules

This commit is contained in:
Marty Oehme 2021-08-28 09:54:41 +02:00
parent 7c606436eb
commit 52fa6474ad
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
4 changed files with 79 additions and 57 deletions

View File

@ -1,52 +0,0 @@
def create_habits(db, trackers):
c = db.cursor()
tracker = trackers["cigarette"]
print(tracker)
habit = (
0, # archived
11, # color (but nomie: `#369DD3`, loop `2` of available selection)
tracker["label"], # name
"smoking", # description (a little one-liner extended description)
1, # freq_den (frequency denominator, either 7 for per week or 30 for per month)
1, # freq_num (frequency numerator, how often per week/month. Has to be one for ranges afaik?)
0, # highlight (function ??)
4, # position (which vertical position on screen tracker takes. must be unique?)
0, # reminder_days (simple int, but i'm not sure how, saw 127)
0, # type (range,counter [more in nomie]; string in nomie, int in loop)
0, # target_type (??)
0.0, # target_value (??)
"c", # unit (text description of value, in nomie set values with `num` being no-value count)
"Did you smoke today?", # question (text question tracker asks)
tracker["id"], # uuid (unique id, must be unique surprisingly)
)
c.execute(
"""INSERT INTO
Habits(id, archived, color, name, description, freq_den, freq_num, highlight, position, reminder_days, type, target_type, target_value, unit, question, uuid)
VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
habit,
)
c.execute("""select * from Habits""")
print(c.fetchall())
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)
"""
)
# grab next tracker info
# look for unique id of next habit
# if exists skip and warn user
# insert tracker into habit table

74
loop/habits.py Normal file
View File

@ -0,0 +1,74 @@
def migrate(db, trackers):
c = db.cursor()
tracker = trackers["cigarette"]
habit_dict = {
"archived": 0,
"color": 11,
"name": tracker["label"],
"description": "smoking",
"freq_den": 1,
"freq_num": 1,
"highlight": 0,
"position": 4,
"question": "Did you smoke today punk?",
"uuid": tracker["id"],
}
add_to_database(c, habit_dict)
# DEBUGGING
c.execute("""select * from Habits""")
print(c.fetchall())
def add_to_database(cursor, habit_dict):
placeholder = ", ".join("?" * len(habit_dict))
columns = ", ".join(habit_dict.keys())
values = list(habit_dict.values())
sql = "insert into `{table}` ({columns}) values ({values});".format(
table="Habits", columns=columns, values=placeholder
)
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,10 @@
import loop.table_constructor as table_constructor
import loop.habit_migrator as habit_migrator
import loop.tables as tables
import loop.habits as habits
def migrate(trackers, events):
db = table_constructor.prepare_database("output.db")
db = tables.migrate("output.db")
if trackers is not None:
habit_migrator.create_habits(db, trackers)
habits.migrate(db, trackers)
db.commit()
db.close()

View File

@ -55,7 +55,7 @@ def create_tables(db):
)
def prepare_database(name):
def migrate(name):
db = create_database(name)
create_tables(db)
return db