Compare commits
	
		
			2 Commits
		
	
	
		
			900fb9f0c0
			...
			d171cf4c5d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d171cf4c5d | |||
| 5080e61abb | 
@ -6,9 +6,9 @@ from the command-line, including:
 | 
				
			|||||||
 - find duplicate activities
 | 
					 - find duplicate activities
 | 
				
			||||||
 - list, move and delete categories, activities and facts
 | 
					 - list, move and delete categories, activities and facts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Merging, renaming and otherwise tidying-up the database used to be possible, but
 | 
					Merging, renaming and otherwise tidying-up the database used to be possible in
 | 
				
			||||||
currently (as of version 2.0.0.16) doesn't work for me, so I wrote this script
 | 
					the Hamster GUI, but currently (as of version 2.0.0.16) doesn't work for me, so
 | 
				
			||||||
to fill in the gap until the [shiny new version of
 | 
					I wrote this script to fill in the gap until the [shiny new version of
 | 
				
			||||||
hamster](https://github.com/projecthamster/hamster-lib) is ready.
 | 
					hamster](https://github.com/projecthamster/hamster-lib) is ready.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $ pip install .
 | 
					    $ pip install .
 | 
				
			||||||
@ -23,8 +23,9 @@ hamster](https://github.com/projecthamster/hamster-lib) is ready.
 | 
				
			|||||||
      activities  Show activities for categories specified by IDS
 | 
					      activities  Show activities for categories specified by IDS
 | 
				
			||||||
      delete      Delete categories specified by IDS
 | 
					      delete      Delete categories specified by IDS
 | 
				
			||||||
      list        List / search categories
 | 
					      list        List / search categories
 | 
				
			||||||
 | 
					      tidy        Delete empty categories
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $ hamster-tools activities 
 | 
					    $ hamster-tools activities --help
 | 
				
			||||||
    Usage: hamster-tools activities [OPTIONS] COMMAND [ARGS]...
 | 
					    Usage: hamster-tools activities [OPTIONS] COMMAND [ARGS]...
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Options:
 | 
					    Options:
 | 
				
			||||||
 | 
				
			|||||||
@ -106,7 +106,7 @@ def delete_categories(ids):
 | 
				
			|||||||
    results = get_categories(ids)
 | 
					    results = get_categories(ids)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for r in results:
 | 
					    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]
 | 
					        count = c.execute(sql, (r[0],)).fetchone()[0]
 | 
				
			||||||
        click.echo('@{0[0]}: {0[1]} ({1} activities)'.format(r, count))
 | 
					        click.echo('@{0[0]}: {0[1]} ({1} activities)'.format(r, count))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -169,6 +169,30 @@ def list_category_activities(ids):
 | 
				
			|||||||
        click.echo('@{0[0]}: {0[2]} » {0[1]}'.format(r))
 | 
					        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()
 | 
					@cli.group()
 | 
				
			||||||
def activities():
 | 
					def activities():
 | 
				
			||||||
    pass
 | 
					    pass
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user