Skip to content

Instantly share code, notes, and snippets.

@byildiz
Created November 5, 2023 22:40
Show Gist options
  • Save byildiz/376bc419c270a36c0f1119f58c75d61c to your computer and use it in GitHub Desktop.
Save byildiz/376bc419c270a36c0f1119f58c75d61c to your computer and use it in GitHub Desktop.
Loop Habit Tracker to Habo
import argparse
import csv
import json
from pathlib import Path
def main(loop_path: Path, habo_path: Path):
habo_habits = []
with loop_path.open() as f:
reader = csv.reader(f)
it = next(reader)
for i, name in enumerate(it[1:-1], start=1):
habo_habits.append(
{
"id": i,
"title": name,
"twoDayRule": 0,
"position": 0,
"cue": "",
"routine": "",
"reward": "",
"showReward": 0,
"advanced": 0,
"notification": 0,
"notTime": "12:0",
"events": {},
"sanction": "",
"showSanction": 0,
"accountant": "",
}
)
for row in reader:
for i, col in enumerate(row[1:-1]):
if col != "-1":
habo_habits[i]["events"][row[0] + " 12:00:00.000Z"] = [
"DayType.check" if col == "2" else "DayType.fail",
"",
]
habo_path.write_text(json.dumps(habo_habits))
if __name__ == "__main__":
parser = argparse.ArgumentParser("loop2habo")
parser.add_argument("loop", help="Loop Habit Tracker CSV export directory")
parser.add_argument(
"--habo",
default="backup.json",
help="Output JSON file path, default: ./backup.json",
)
args = parser.parse_args()
loop_path = Path(f"{args.loop}/Checkmarks.csv")
habo_path = Path(args.habo)
main(loop_path, habo_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment