diff --git a/loop/habit_migrator.py b/loop/habit_migrator.py new file mode 100644 index 0000000..f0409e3 --- /dev/null +++ b/loop/habit_migrator.py @@ -0,0 +1,18 @@ +def create_habits(db, trackers): + print("migrating habits, yo") + c = db.cursor() + tracker = trackers["cigarette"] + print(tracker) + # for when the execute works, can be filled in its own function + habit = ( + tracker["label"], + 0, + 0, + tracker["id"], + ) + c.execute( + """INSERT INTO + Habits(id, name, position, type, uuid) + VALUES (NULL, ?, ?, ?, ?)""", + habit, + ) diff --git a/loop/migration.py b/loop/migration.py new file mode 100644 index 0000000..2d6e5c2 --- /dev/null +++ b/loop/migration.py @@ -0,0 +1,9 @@ +import loop.table_constructor as table_constructor +import loop.habit_migrator as habit_migrator + + +def migrate(trackers, events): + db = table_constructor.prepare_database("output.db") + if trackers is not None: + habit_migrator.create_habits(db, trackers) + db.commit() diff --git a/toloop.py b/loop/table_constructor.py similarity index 77% rename from toloop.py rename to loop/table_constructor.py index b636a76..2231715 100644 --- a/toloop.py +++ b/loop/table_constructor.py @@ -5,6 +5,22 @@ def create_database(name): return sqlite3.connect(name) +# better way to do the above +# def create_connection(db_file): +# """create a database connection to the SQLite database +# specified by db_file +# :param db_file: database file +# :return: Connection object or None +# """ +# conn = None +# try: +# conn = sqlite3.connect(db_file) +# return conn +# except Error as e: +# print(e) +# return conn + + def create_tables(db): c = db.cursor() c.execute( @@ -39,6 +55,7 @@ def create_tables(db): ) -def migrate(trackers, events): - db = create_database("output.db") +def prepare_database(name): + db = create_database(name) create_tables(db) + return db diff --git a/migrate.py b/migrate.py index 9e10952..5ff8ef8 100755 --- a/migrate.py +++ b/migrate.py @@ -1,8 +1,9 @@ #!/usr/bin/env python import json +import sys import pandas as pd -import toloop as loop +import loop.migration as loop def load_file(filename): @@ -41,25 +42,9 @@ def verify_continue(data): exit(0) -# better way to do this -# def create_connection(db_file): -# """create a database connection to the SQLite database -# specified by db_file -# :param db_file: database file -# :return: Connection object or None -# """ -# conn = None -# try: -# conn = sqlite3.connect(db_file) -# return conn -# except Error as e: -# print(e) -# return conn - - if __name__ == "__main__": # load nomie json - nomie_data = load_file("input.json") + nomie_data = load_file(sys.argv[1]) # DISABLED FOR DEBUGGING verify_continue(nomie_data) trackers = nomie_data["trackers"]