Compare commits

..

No commits in common. "d171cf4c5d61ca507a475c47e7e9f967fd5a5d7c" and "900fb9f0c044c06753bb6fc8c88899d0635aafb8" have entirely different histories.

2 changed files with 5 additions and 30 deletions

View File

@ -6,9 +6,9 @@ from the command-line, including:
- find duplicate activities
- list, move and delete categories, activities and facts
Merging, renaming and otherwise tidying-up the database used to be possible in
the Hamster GUI, but currently (as of version 2.0.0.16) doesn't work for me, so
I wrote this script to fill in the gap until the [shiny new version of
Merging, renaming and otherwise tidying-up the database used to be possible, but
currently (as of version 2.0.0.16) doesn't work for me, so I wrote this script
to fill in the gap until the [shiny new version of
hamster](https://github.com/projecthamster/hamster-lib) is ready.
$ pip install .
@ -23,9 +23,8 @@ hamster](https://github.com/projecthamster/hamster-lib) is ready.
activities Show activities for categories specified by IDS
delete Delete categories specified by IDS
list List / search categories
tidy Delete empty categories
$ hamster-tools activities --help
$ hamster-tools activities
Usage: hamster-tools activities [OPTIONS] COMMAND [ARGS]...
Options:

View File

@ -106,7 +106,7 @@ def delete_categories(ids):
results = get_categories(ids)
for r in results:
sql = 'select count(id) from activities where category_id = ?'
sql = 'SELECT COUNT(id) FROM activities WHERE category_id = ?'
count = c.execute(sql, (r[0],)).fetchone()[0]
click.echo('@{0[0]}: {0[1]} ({1} activities)'.format(r, count))
@ -169,30 +169,6 @@ def list_category_activities(ids):
click.echo('@{0[0]}: {0[2]} » {0[1]}'.format(r))
@categories.command('tidy')
def tidy_categories():
""" Remove categories with no activities """
sql = 'SELECT categories.id, categories.name FROM categories LEFT JOIN activities ON categories.id = activities.category_id WHERE activities.id IS NULL'
categories = c.execute(sql).fetchall()
click.echo('Found {0} empty categories:'.format(len(categories)))
for cat in categories:
click.echo('@{0[0]}: {0[1]}'.format(cat))
click.confirm('Do you want to continue?', abort=True)
sql = 'DELETE FROM categories '
sql = sql + 'WHERE id IN ({seq})'.format(
seq=','.join(['?'] * len(categories))
)
c.execute(sql, [cat[0] for cat in categories])
conn.commit()
@cli.group()
def activities():
pass