Tweak reqs, add rename_category, etc.

This commit is contained in:
3wc 2021-09-07 23:53:36 +02:00
parent 704206ae7c
commit a3aef30826
2 changed files with 33 additions and 3 deletions

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",
]
)