kimai sync --just-errors and --ignore-activities
This commit is contained in:
parent
385eb44a71
commit
acc3153fba
@ -402,7 +402,9 @@ def _get_kimai_mapping_file(path):
|
||||
@click.option('--mapping-path', help='Mapping file (default ~/.local/share/hamster/mapping.kimai.csv)')
|
||||
@click.argument('username')
|
||||
@click.argument('api_key')
|
||||
def sync(username, api_key, mapping_path=None):
|
||||
@click.option('--just-errors', 'just_errors', is_flag=True, help='Only display errors')
|
||||
@click.option('--ignore-activities', is_flag=True, help='Ignore missing activities')
|
||||
def sync(username, api_key, just_errors, ignore_activities, mapping_path=None):
|
||||
"""
|
||||
Download customer / project / activity data from Kimai
|
||||
"""
|
||||
@ -428,9 +430,9 @@ def sync(username, api_key, mapping_path=None):
|
||||
'X-AUTH-TOKEN': api_key
|
||||
}
|
||||
|
||||
customers = requests.get(f'{kimai_api_url}/customers', headers=auth_headers).json()
|
||||
projects = requests.get(f'{kimai_api_url}/projects', headers=auth_headers).json()
|
||||
activities = requests.get(f'{kimai_api_url}/activities', headers=auth_headers).json()
|
||||
customers = requests.get(f'{kimai_api_url}/customers?visible=3', headers=auth_headers).json()
|
||||
projects = requests.get(f'{kimai_api_url}/projects?visible=3', headers=auth_headers).json()
|
||||
activities = requests.get(f'{kimai_api_url}/activities?visible=3', headers=auth_headers).json()
|
||||
|
||||
found_customers = []
|
||||
found_projects = []
|
||||
@ -441,7 +443,7 @@ def sync(username, api_key, mapping_path=None):
|
||||
|
||||
matching_customers = list(filter(lambda x: x['name'] == row[0], customers))
|
||||
if row[0] in found_customers:
|
||||
click.secho("Skipping existing customer '{0}'".format(row[0]), fg='green')
|
||||
just_errors or click.secho("Skipping existing customer '{0}'".format(row[0]), fg='green')
|
||||
else:
|
||||
if len(matching_customers) > 1:
|
||||
click.secho("More than one match for customer '{0}'".format(row[0]), fg='red')
|
||||
@ -450,7 +452,7 @@ def sync(username, api_key, mapping_path=None):
|
||||
click.secho("Missing customer '{0}'".format(row[0]), fg='yellow')
|
||||
continue
|
||||
else:
|
||||
click.secho("Found customer '{0}'".format(row[0]), fg='green')
|
||||
just_errors or click.secho("Found customer '{0}'".format(row[0]), fg='green')
|
||||
found_customers.append(row[0])
|
||||
|
||||
project_str = ':'.join(row[0:2])
|
||||
@ -461,7 +463,7 @@ def sync(username, api_key, mapping_path=None):
|
||||
)
|
||||
|
||||
if project_str in found_projects:
|
||||
click.secho("Skipping existing project '{0}'".format(project_str), fg='green')
|
||||
just_errors or click.secho("Skipping existing project '{0}'".format(project_str), fg='green')
|
||||
else:
|
||||
if len(matching_projects) > 1:
|
||||
click.secho("More than one match for project '{0}'".format(project_str), fg='red')
|
||||
@ -470,12 +472,15 @@ def sync(username, api_key, mapping_path=None):
|
||||
click.secho("Missing project '{0}'".format(project_str), fg='yellow')
|
||||
continue
|
||||
else:
|
||||
click.secho("Found project '{0}'".format(project_str), fg='green')
|
||||
just_errors or click.secho("Found project '{0}'".format(project_str), fg='green')
|
||||
found_projects.append(project_str)
|
||||
|
||||
if ignore_activities:
|
||||
continue
|
||||
|
||||
activity_str = ':'.join(row)
|
||||
if activity_str in found_activities:
|
||||
click.secho("Skipping existing activity '{0}'".format(activity_str), fg='green')
|
||||
just_errors or click.secho("Skipping existing activity '{0}'".format(activity_str), fg='green')
|
||||
else:
|
||||
matching_activities = list(filter(
|
||||
lambda x: x['name'] == row[2]
|
||||
@ -488,7 +493,7 @@ def sync(username, api_key, mapping_path=None):
|
||||
elif len(matching_activities) < 1:
|
||||
click.secho("Missing activity '{0}'".format(activity_str), fg='yellow')
|
||||
else:
|
||||
click.secho("Found activity '{0}'".format(activity_str), fg='green')
|
||||
just_errors or click.secho("Found activity '{0}'".format(activity_str), fg='green')
|
||||
found_activities.append(activity_str)
|
||||
|
||||
@kimai.command('import')
|
||||
|
Loading…
Reference in New Issue
Block a user