2021-08-26 19:57:49 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import json
|
2021-08-27 08:55:31 +00:00
|
|
|
import sys
|
2021-08-28 08:35:29 +00:00
|
|
|
|
2021-08-27 08:55:31 +00:00
|
|
|
import loop.migration as loop
|
2021-08-26 19:57:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
def load_file(filename):
|
|
|
|
with open(filename) as f:
|
|
|
|
nomie_data = json.load(f)
|
|
|
|
return nomie_data
|
|
|
|
|
|
|
|
|
2021-08-26 21:13:56 +00:00
|
|
|
# generate a yes/no cli question with a default answer
|
2021-08-26 19:57:49 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2021-08-26 21:13:56 +00:00
|
|
|
# display stats and ask user to confirm if they seem okay
|
2021-08-26 19:57:49 +00:00
|
|
|
def verify_continue(data):
|
|
|
|
trackers = ""
|
|
|
|
for t in data["trackers"]:
|
|
|
|
trackers += t + ", "
|
2021-08-27 08:11:00 +00:00
|
|
|
print(f"Exporting from nomie {data['nomie']['number']}:")
|
2021-08-26 19:57:49 +00:00
|
|
|
print(f"Found trackers: {trackers}")
|
2021-08-27 08:11:00 +00:00
|
|
|
print(f"Found events: {len(data['events'])} entries.")
|
2021-08-26 19:57:49 +00:00
|
|
|
if not confirmation_question("Do you want to continue?", default_no=False):
|
|
|
|
print("Aborted.")
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# load nomie json
|
2021-08-27 08:55:31 +00:00
|
|
|
nomie_data = load_file(sys.argv[1])
|
2021-08-26 19:57:49 +00:00
|
|
|
verify_continue(nomie_data)
|
2021-08-27 08:11:00 +00:00
|
|
|
trackers = nomie_data["trackers"]
|
|
|
|
events = nomie_data["events"]
|
2021-08-26 19:57:49 +00:00
|
|
|
|
2021-08-27 08:11:00 +00:00
|
|
|
# give it over to loop migrator
|
|
|
|
loop.migrate(trackers, events)
|