70 lines
1.9 KiB
Python
Executable file
70 lines
1.9 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import json
|
|
import sqlite3
|
|
|
|
|
|
def load_file(filename):
|
|
with open(filename) as f:
|
|
nomie_data = json.load(f)
|
|
return nomie_data
|
|
|
|
|
|
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
|
|
|
|
|
|
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(cursor):
|
|
cursor.execute("CREATE TABLE ")
|
|
|
|
|
|
# HABITS
|
|
# id|archived|color|description|freq_den|freq_num|highlight|name|position|reminder_hour|reminder_min|reminder_days|type|target_type|target_value|unit|question|uuid
|
|
# 1|0|4||1|1|0|mood|0|||0|1|0|10.0||How do you feel today?|d183a7dd755e44ce9a5782f518b402b4
|
|
# 2|0|1||1|1|0|reading|1|||0|0|0|0.0||Did you read today?|6b361353e0914a698e896798d5ebca6e
|
|
# 3|0|15||1|1|0|sex 💏|2|||0|0|0|0.0||Did you have sex today?|41b646162dc542b3ba223993847d861b
|
|
|
|
# CHAINS - habit maps to habit table ID
|
|
# id|habit|timestamp|value
|
|
# 1|1|1627257600000|5000
|
|
# 2|2|1627257600000|2
|
|
# 3|2|1627171200000|2
|
|
# 4|2|1626998400000|2
|
|
# 5|1|1626912000000|10000
|
|
# 6|1|1626998400000|3000
|
|
# 7|3|1627171200000|2
|
|
|
|
# EVENTS -- empty?
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# load nomie json
|
|
nomie_data = load_file("input.json")
|
|
verify_continue(nomie_data)
|
|
|
|
# prep sqlite database
|
|
db = create_database("output.db")
|
|
c = db.cursor()
|