habitmove/migrate.py

73 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python
import json
import pandas as pd
import toloop as loop
def load_file(filename):
with open(filename) as f:
nomie_data = json.load(f)
return nomie_data
def get_dataframe(nomie_data):
return pd.DataFrame(nomie_data["events"])
# generate a yes/no cli question with a default answer
def confirmation_question(question, default_no=True):
choices = " [y/N]: " if default_no else " [Y/n]: "
default_answer = "n" if default_no else "y"
reply = str(input(question + choices)).lower().strip() or default_answer
if reply[0] == "y":
return True
if reply[0] == "n":
return False
else:
return False if default_no else True
# display stats and ask user to confirm if they seem okay
def verify_continue(data):
trackers = ""
for t in data["trackers"]:
trackers += t + ", "
print(f"Exporting from nomie {data['nomie']['number']}:")
print(f"Found trackers: {trackers}")
print(f"Found events: {len(data['events'])} entries.")
if not confirmation_question("Do you want to continue?", default_no=False):
print("Aborted.")
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")
# DISABLED FOR DEBUGGING
verify_continue(nomie_data)
trackers = nomie_data["trackers"]
events = nomie_data["events"]
# bring up dataframe
df = get_dataframe(nomie_data)
# give it over to loop migrator
loop.migrate(trackers, events)