From 40c0312e4c5336460756930b545ea8c1c69c11e5 Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Thu, 12 Jan 2023 16:34:51 -0800 Subject: [PATCH] Sort entries, fix docs --- README.md | 4 ++-- hamstertools/__init__.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d56ca9b..c098a15 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,9 @@ hamster](https://github.com/projecthamster/hamster-lib) is ready. ## Importing into Kimai -1. Run `hamster-tool activities list --csv` to get a dump of all activities +1. Run `python -m hamstertools activities list --csv` to get a dump of all activities 2. Review the export to check for any duplicates, typoes, etc. -3. Use e.g. `hamster-tool activities move-facts ...` to clean them up +3. Use e.g. `python -m hamstertools activities move-facts ...` to clean them up 4. Run `python -m hamstertools kimai import --mapping-path mapping.kimai.csv --show-missing --after 2021-09-07 --category-search auto 3wordchant` to find entries in your time tracking which don't yet have a mapping to Kimai. You might notice some extra tidying needed here. 5. Run `python -m hamstertools kimai sync --mapping-path mapping.kimai.csv --just-errors --ignore-activities 3wordchant $(pass users/calix/logins/kimai.autonomic.zone/api)` to find items in your mapping file which don't exist on Kimai 5. Run `python -m hamstertools kimai import --mapping-path mapping.kimai.csv --after 2021-09-07 --category-search auto 3wordchant --output kimai_$(date +%F).csv` to generate a CSV of your time entries diff --git a/hamstertools/__init__.py b/hamstertools/__init__.py index fcef0b2..e7e21de 100755 --- a/hamstertools/__init__.py +++ b/hamstertools/__init__.py @@ -206,6 +206,8 @@ def list_activities(search, csv_output): results = get_activities(search=search) + results.sort(key=lambda t: (t[2], t[1])) + if csv_output: csv_writer = csv.writer(sys.stdout) @@ -412,7 +414,9 @@ def _get_kimai_mapping_file(path): 'FROM activity', 'TO Customer', 'TO Project', - 'TO Activity' + 'TO Activity', + 'TO Tag', + 'TO Note' ]) results = get_activities(category_search=category_search) @@ -644,6 +648,9 @@ def _import(username, mapping_path=None, output=None, category_search=None, afte ), fg='yellow') continue + if len(mapping_) < 5: + mapping_.append(None) + date_start, date_end = ( datetime.strptime(fact[2].split('.')[0], '%Y-%m-%d %H:%M:%S'), datetime.strptime(fact[1].split('.')[0], '%Y-%m-%d %H:%M:%S') @@ -662,7 +669,7 @@ def _import(username, mapping_path=None, output=None, category_search=None, afte mapping_[0], mapping_[1], mapping_[2], - fact[3] or '', + fact[3] or mapping_[4] or '', '0', # Exported mapping_[3], '', # Hourly rate