From 1a5004e333850373713533383c4e63e0c57a9ecb Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 28 Aug 2021 22:03:45 +0200 Subject: [PATCH] Add range habits --- CHANGELOG.md | 2 ++ README.md | 15 ++++++++++++++- loop/habits.py | 5 +++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cfa774..7ad0ec2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe ## [Unreleased] +* Add range habits, translating nomie max value to range target in Loop + ## [0.2.1] - 2021-08-28 ### Fixed diff --git a/README.md b/README.md index 1c2e5b8..8fcb3d0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,16 @@ +# Nomie Habit Migrator + +Can take an export of nomie habits in json format and convert it to be importable in Loop Habit Tracker. + +Confirmed working for nomie version 5.6.4 and Loop Habit Tracker version 2.0.2. +Presumably works for other nomie 5.x versions and other Loop 2.x versions as well, but is untested. + +## Usage + +Currently takes a single argument, the nomie database file, and will output to `output.db` in present working directory. + +Invoked like: `python migrate.py nomie-export.json` + # Schemas A collection of the schemas of Loop habit sqlite database for later migration @@ -59,7 +72,7 @@ label + emoji | name ? | reminder_days (simple int, but i'm not sure how, saw 127) type | type (range,counter [more in nomie]; string in nomie, int in loop) ? | target_type (??) -? | target_value (??) +? | target_value (maximum value for range habits afaik) uom | unit (text description of value, in nomie set values with `num` being no-value count) ? | question (text question tracker asks) id | uuid (unique id, must be unique surprisingly) diff --git a/loop/habits.py b/loop/habits.py index ec04e9f..8f63567 100644 --- a/loop/habits.py +++ b/loop/habits.py @@ -15,7 +15,6 @@ def migrate(db, trackers): def trackers_to_habits(trackers): habits = [] - # for each list entry tracker dict transform to habit dict for tracker_name in trackers.keys(): t = trackers[tracker_name] habits.append( @@ -32,8 +31,10 @@ def trackers_to_habits(trackers): "unit": "" if t["uom"] == "num" else t["uom"], "uuid": t["id"], } - # FIXME conditional for ranges (if type = range > habits[-1]['type'] = intforrangetype; habits[-1]['max'] =) ) + if t["type"] == "range" and len(habits) > 0: + habits[-1]["type"] = "1" + habits[-1]["target_value"] = t["max"] return habits