92 lines
2.9 KiB
Python
Executable file
92 lines
2.9 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import json
|
|
import pandas as pd
|
|
import sqlite3
|
|
|
|
|
|
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"Found trackers: {trackers}")
|
|
print(f"with {len(data['events'])} event entries.")
|
|
if not confirmation_question("Do you want to continue?", default_no=False):
|
|
print("Aborted.")
|
|
exit(0)
|
|
|
|
|
|
def create_database(name):
|
|
return sqlite3.connect(name)
|
|
|
|
|
|
def create_loop_tables(db):
|
|
c = db.cursor()
|
|
c.execute(
|
|
""" CREATE TABLE IF NOT EXISTS Habits (
|
|
id integer PRIMARY KEY,
|
|
archived integer,
|
|
color integer,
|
|
description text,
|
|
freq_den integer,
|
|
freq_num integer,
|
|
highlight integer,
|
|
name text NOT NULL,
|
|
position integer,
|
|
reminder_hour integer,
|
|
reminder_min integer,
|
|
reminder_days integer,
|
|
type integer,
|
|
target_type integer,
|
|
target_value real,
|
|
unit text,
|
|
question text,
|
|
uuid text NOT NULL
|
|
); """
|
|
)
|
|
c.execute(
|
|
""" CREATE TABLE IF NOT EXISTS Repetitions (
|
|
id integer PRIMARY KEY,
|
|
habit integer,
|
|
timestamp integer,
|
|
value integer
|
|
); """
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# load nomie json
|
|
nomie_data = load_file("input.json")
|
|
# DISABLED FOR DEBUGGING
|
|
verify_continue(nomie_data)
|
|
|
|
# bring up dataframe
|
|
df = get_dataframe(nomie_data)
|
|
|
|
# prep sqlite database
|
|
db = create_database("output.db")
|
|
create_loop_tables(db)
|