From 52fa6474ad2c399a8c537a78a090c27206f5a595 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 28 Aug 2021 09:54:41 +0200 Subject: [PATCH] Rename loop import modules --- loop/habit_migrator.py | 52 ----------------- loop/habits.py | 74 ++++++++++++++++++++++++ loop/migration.py | 8 +-- loop/{table_constructor.py => tables.py} | 2 +- 4 files changed, 79 insertions(+), 57 deletions(-) delete mode 100644 loop/habit_migrator.py create mode 100644 loop/habits.py rename loop/{table_constructor.py => tables.py} (98%) diff --git a/loop/habit_migrator.py b/loop/habit_migrator.py deleted file mode 100644 index 6f274dd..0000000 --- a/loop/habit_migrator.py +++ /dev/null @@ -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 diff --git a/loop/habits.py b/loop/habits.py new file mode 100644 index 0000000..d0ad05d --- /dev/null +++ b/loop/habits.py @@ -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) +# """ +# ) +# """ +# ) +# """ +# ) +# """ +# ) +# """ +# ) +# """ +# ) +# """ +# ) +# """ +# ) +# """ +# ) +# """ +# ) +# """ +# ) diff --git a/loop/migration.py b/loop/migration.py index dde89d1..a3a2c23 100644 --- a/loop/migration.py +++ b/loop/migration.py @@ -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() diff --git a/loop/table_constructor.py b/loop/tables.py similarity index 98% rename from loop/table_constructor.py rename to loop/tables.py index 4cf7ec3..fd5788c 100644 --- a/loop/table_constructor.py +++ b/loop/tables.py @@ -55,7 +55,7 @@ def create_tables(db): ) -def prepare_database(name): +def migrate(name): db = create_database(name) create_tables(db) return db