Fix ability to be run via poetry and cli

Program can now be invoked through poetry for development purposes,
invoke as follows from main directory: `poetry run move`.

Alternatively, can still be invoked via `python run.py <nomie-json>` and
now via `./run.py <nomie-json>` which uses system default python
installation. For now both commands are only mainly useful from the
poetry development virtual environment itself.
This commit is contained in:
Marty Oehme 2021-09-30 17:19:29 +02:00
parent 6af4638845
commit bea6c0eca5
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
10 changed files with 65 additions and 35 deletions

View File

@ -7,6 +7,12 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe
## [Unreleased]
## [0.3.1] - 2021-09-30
### Fixed
* Fix ability to run via poetry or be invoked from command-line
### Removed
* Remove pandas dependency and dataframe functionality

View File

@ -3,7 +3,8 @@
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.
Presumably works for other nomie 5.x versions and other Loop 2.x versions as well,
but that is untested.
## Usage
@ -11,9 +12,16 @@ Currently takes a single argument, the nomie database file, and will output to `
Can also take an existing Loop Habit database (exported from the application),
and add the nomie exported habits and checkmarks to it.
Simply put the exported Loop database in the same directory and call it `output.db`,
it will not (should not) overwrite anything.
it will not (should not™️) overwrite anything.
Invoked like: `python migrate.py nomie-export.json`
Invoked like: `python run.py nomie-export.json`.
Note, however, that -- until a packaged version is released -- you will need to have some packages in your environment.
If you wish to run it un-packaged, install poetry and let it do all dependency management by doing:
```
poetry install
poetry run habitmove <nomie-json>
```
# Schemas

4
habitmove/__init__.py Normal file
View File

@ -0,0 +1,4 @@
import habitmove.schema as schema
import habitmove.habits as habits
import habitmove.repetitions as rep
import habitmove.nomie as nomie

14
migrate.py → habitmove/nomie.py Executable file → Normal file
View File

@ -1,9 +1,6 @@
#!/usr/bin/env python
import json
import sys
import loop.migration as loop
def load_file(filename):
@ -36,14 +33,3 @@ def verify_continue(data):
if not confirmation_question("Do you want to continue?", default_no=False):
print("Aborted.")
exit(0)
if __name__ == "__main__":
# load nomie json
nomie_data = load_file(sys.argv[1])
verify_continue(nomie_data)
trackers = nomie_data["trackers"]
events = nomie_data["events"]
# give it over to loop migrator
loop.migrate(trackers, events)

View File

@ -1,16 +0,0 @@
import loop.schema as schema
import loop.habits as habits
import loop.repetitions as rep
def migrate(trackers, events):
db = schema.migrate("output.db")
if trackers is not None:
habitlist = habits.migrate(db, trackers)
if events is not None:
rep.migrate(db, habitlist, events)
db.commit()
db.close()

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "nomie-migration"
version = "0.3.0"
name = "habitmove"
version = "0.3.1"
description = "migrate nomie data to loop habits tracker"
authors = ["Marty Oehme <marty.oehme@gmail.com>"]
@ -9,6 +9,10 @@ python = "^3.9"
[tool.poetry.dev-dependencies]
[tool.poetry.scripts]
habitmove = "run:main"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

38
run.py Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python
import habitmove.schema as schema
import habitmove.habits as habits
import habitmove.repetitions as rep
import habitmove.nomie as nomie
import sys
def migrate(trackers, events):
db = schema.migrate("output.db")
if trackers is not None:
habitlist = habits.migrate(db, trackers)
if events is not None:
rep.migrate(db, habitlist, events)
db.commit()
db.close()
def main():
# load nomie json
nomie_data = nomie.load_file(sys.argv[1])
nomie.verify_continue(nomie_data)
trackers = nomie_data["trackers"]
events = nomie_data["events"]
migrate(trackers, events)
if __name__ == "__main__":
main()
# things to have as (data) classes:
# tracker, event, tag?
# habit, repetition