Compare commits

...

2 Commits

Author SHA1 Message Date
3wc
a3aef30826 Tweak reqs, add rename_category, etc. 2021-09-07 23:53:36 +02:00
3wc
704206ae7c Add kimai to READMe 2021-09-07 23:51:01 +02:00
3 changed files with 41 additions and 5 deletions

View File

@ -1,5 +1,4 @@
hamster-tools
------------
# hamster-tools
Manipulate [hamster-time-tracker](https://github.com/projecthamster/) data
from the command-line, including:
@ -47,3 +46,10 @@ hamster](https://github.com/projecthamster/hamster-lib) is ready.
Commands:
kimai Export time tracking data in Kimai format
## Importing into Kimai
1. Run `hamster-tool 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
4.

View File

@ -8,7 +8,7 @@ import click
import requests
import sqlite3
HAMSTER_DIR = Path.home() / '.local/share/hamster-applet'
HAMSTER_DIR = Path.home() / '.local/share/hamster'
HAMSTER_FILE = HAMSTER_DIR / 'hamster.db'
conn = sqlite3.connect(HAMSTER_FILE)
@ -112,6 +112,10 @@ def delete_categories(ids):
click.confirm('Do you want to continue?', abort=True)
for r in results:
sql = 'DELETE FROM activities WHERE category_id = ?'
c.execute(sql, (r[0],))
sql = 'DELETE FROM categories '
sql = sql + 'WHERE id IN ({seq})'.format(
@ -124,6 +128,21 @@ def delete_categories(ids):
click.secho('Deleted {0} categories'.format(len(ids)), fg='green')
@categories.command('rename')
@click.argument('id_', metavar='ID')
@click.argument('name')
def rename_category(id_, name):
""" Rename a category """
r = get_categories((id_,))[0]
click.echo('Renaming @{0[0]}: {0[1]} to "{1}"'.format(r, name))
sql = 'UPDATE categories SET name = ? WHERE id = ?'
c.execute(sql, (name, r[0]))
conn.commit()
@categories.command('activities')
@click.argument('ids', nargs=-1)
def list_category_activities(ids):
@ -307,6 +326,13 @@ def move_facts(from_id, to_id):
click.secho('Moved {0} facts'.format(results.rowcount), fg='green')
click.confirm(
'Would you like to delete @{0[2]} » @{0[0]}: {0[1]}?'.format(from_activity),
abort=True
)
delete_activities((from_id,))
@activities.command()
def find_duplicates():

View File

@ -6,8 +6,8 @@ with open("README.md", "r") as fh:
setuptools.setup(
name="hamster-tools", # Replace with your own username
version="0.0.1",
author="Carl van Tonder",
author_email="carl@supervacuo.com",
author="calix",
author_email="3wc.python@doesthisthing.work",
description="Manage hamster-time-tracker data",
long_description=long_description,
long_description_content_type="text/markdown",
@ -23,4 +23,8 @@ setuptools.setup(
[console_scripts]
hamster-tools=hamstertools:cli
''',
install_requires=[
"click >= 8.0.1",
"requests >= 2.25.1",
]
)