Run autopep8
This commit is contained in:
		@ -94,7 +94,7 @@ def list_categories(search):
 | 
			
		||||
    results = get_categories(search=search)
 | 
			
		||||
 | 
			
		||||
    for r in results:
 | 
			
		||||
         click.echo('@{0[0]}: {0[1]}'.format(r))
 | 
			
		||||
        click.echo('@{0[0]}: {0[1]}'.format(r))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@categories.command('delete')
 | 
			
		||||
@ -129,8 +129,8 @@ def delete_categories(ids):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@categories.command('rename')
 | 
			
		||||
@click.argument('id_', metavar='ID') 
 | 
			
		||||
@click.argument('name') 
 | 
			
		||||
@click.argument('id_', metavar='ID')
 | 
			
		||||
@click.argument('name')
 | 
			
		||||
def rename_category(id_, name):
 | 
			
		||||
    """ Rename a category """
 | 
			
		||||
 | 
			
		||||
@ -163,10 +163,10 @@ def list_category_activities(ids):
 | 
			
		||||
        seq=','.join(['?'] * len(ids))
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    results =  c.execute(sql, ids)
 | 
			
		||||
    results = c.execute(sql, ids)
 | 
			
		||||
 | 
			
		||||
    for r in results:
 | 
			
		||||
         click.echo('@{0[0]}: {0[2]} » {0[1]}'.format(r))
 | 
			
		||||
        click.echo('@{0[0]}: {0[2]} » {0[1]}'.format(r))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@cli.group()
 | 
			
		||||
@ -231,7 +231,7 @@ def move(category_id, ids):
 | 
			
		||||
    click.secho('Moving to "@{0[0]}: {0[1]}":'.format(category), fg='green')
 | 
			
		||||
 | 
			
		||||
    for r in results:
 | 
			
		||||
         click.secho('@{0[3]}: {0[2]} » @{0[0]}: {0[1]}'.format(r), fg='blue')
 | 
			
		||||
        click.secho('@{0[3]}: {0[2]} » @{0[0]}: {0[1]}'.format(r), fg='blue')
 | 
			
		||||
 | 
			
		||||
    click.confirm('Do you want to continue?', abort=True)
 | 
			
		||||
 | 
			
		||||
@ -281,7 +281,8 @@ def list_facts(ids):
 | 
			
		||||
        results = c.execute(sql, (r[0],))
 | 
			
		||||
 | 
			
		||||
        for r in results:
 | 
			
		||||
             click.secho('@{0[0]}, {0[1]}'.format(r), fg='blue')
 | 
			
		||||
            click.secho('@{0[0]}, {0[1]}'.format(r), fg='blue')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@activities.command()
 | 
			
		||||
@click.argument('from_id')
 | 
			
		||||
@ -314,7 +315,7 @@ def move_facts(from_id, to_id):
 | 
			
		||||
    results = c.execute(sql, (from_id,))
 | 
			
		||||
 | 
			
		||||
    for r in results:
 | 
			
		||||
         click.secho('@{0[0]}, {0[1]}'.format(r), fg='blue')
 | 
			
		||||
        click.secho('@{0[0]}, {0[1]}'.format(r), fg='blue')
 | 
			
		||||
 | 
			
		||||
    click.confirm('Do you want to continue?', abort=True)
 | 
			
		||||
 | 
			
		||||
@ -328,7 +329,8 @@ 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), 
 | 
			
		||||
        'Would you like to delete @{0[2]} » @{0[0]}: {0[1]}?'.format(
 | 
			
		||||
            from_activity),
 | 
			
		||||
        abort=True
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
@ -361,7 +363,8 @@ def find_duplicates():
 | 
			
		||||
    results = c.execute(sql)
 | 
			
		||||
 | 
			
		||||
    for r in results:
 | 
			
		||||
         click.secho('@{0[0]}: {0[1]} » @{0[2]}: {0[3]} ({0[4]})'.format(r), fg='blue')
 | 
			
		||||
        click.secho(
 | 
			
		||||
            '@{0[0]}: {0[1]} » @{0[2]}: {0[3]} ({0[4]})'.format(r), fg='blue')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@cli.group()
 | 
			
		||||
@ -431,9 +434,12 @@ def sync(username, api_key, just_errors, ignore_activities, mapping_path=None):
 | 
			
		||||
        'X-AUTH-TOKEN': api_key
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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()
 | 
			
		||||
    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 = []
 | 
			
		||||
@ -442,38 +448,47 @@ def sync(username, api_key, just_errors, ignore_activities, mapping_path=None):
 | 
			
		||||
    for row in mapping_data:
 | 
			
		||||
        # Check if each mapping still exists in Kimai
 | 
			
		||||
 | 
			
		||||
        matching_customers = list(filter(lambda x: x['name'] == row[0], customers))
 | 
			
		||||
        matching_customers = list(
 | 
			
		||||
            filter(lambda x: x['name'] == row[0], customers))
 | 
			
		||||
        if row[0] in found_customers:
 | 
			
		||||
            just_errors or 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')
 | 
			
		||||
                click.secho(
 | 
			
		||||
                    "More than one match for customer '{0}'".format(row[0]), fg='red')
 | 
			
		||||
                continue
 | 
			
		||||
            elif len(matching_customers) < 1:
 | 
			
		||||
                click.secho("Missing customer '{0}'".format(row[0]), fg='yellow')
 | 
			
		||||
                click.secho("Missing customer '{0}'".format(
 | 
			
		||||
                    row[0]), fg='yellow')
 | 
			
		||||
                continue
 | 
			
		||||
            else:
 | 
			
		||||
                just_errors or 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])
 | 
			
		||||
        matching_projects = list(filter(
 | 
			
		||||
            lambda x: x['name'] == row[1] and
 | 
			
		||||
                x['customer'] == matching_customers[0]['id'], 
 | 
			
		||||
            x['customer'] == matching_customers[0]['id'],
 | 
			
		||||
            projects)
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        if project_str in found_projects:
 | 
			
		||||
            just_errors or 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')
 | 
			
		||||
                click.secho("More than one match for project '{0}'".format(
 | 
			
		||||
                    project_str), fg='red')
 | 
			
		||||
                continue
 | 
			
		||||
            elif len(matching_projects) < 1:
 | 
			
		||||
                click.secho("Missing project '{0}'".format(project_str), fg='yellow')
 | 
			
		||||
                click.secho("Missing project '{0}'".format(
 | 
			
		||||
                    project_str), fg='yellow')
 | 
			
		||||
                continue
 | 
			
		||||
            else:
 | 
			
		||||
                just_errors or 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:
 | 
			
		||||
@ -481,20 +496,24 @@ def sync(username, api_key, just_errors, ignore_activities, mapping_path=None):
 | 
			
		||||
 | 
			
		||||
        activity_str = ':'.join(row)
 | 
			
		||||
        if activity_str in found_activities:
 | 
			
		||||
            just_errors or 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] 
 | 
			
		||||
                    and x['project'] == matching_projects[0]['id'], 
 | 
			
		||||
                lambda x: x['name'] == row[2]
 | 
			
		||||
                and x['project'] == matching_projects[0]['id'],
 | 
			
		||||
                activities
 | 
			
		||||
            ))
 | 
			
		||||
 | 
			
		||||
            if len(matching_activities) > 1:
 | 
			
		||||
                click.secho("More than one match for activity '{0}'".format(activity_str), fg='red')
 | 
			
		||||
                click.secho("More than one match for activity '{0}'".format(
 | 
			
		||||
                    activity_str), fg='red')
 | 
			
		||||
            elif len(matching_activities) < 1:
 | 
			
		||||
                click.secho("Missing activity '{0}'".format(activity_str), fg='yellow')
 | 
			
		||||
                click.secho("Missing activity '{0}'".format(
 | 
			
		||||
                    activity_str), fg='yellow')
 | 
			
		||||
            else:
 | 
			
		||||
                just_errors or 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)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -587,7 +606,8 @@ def _import(username, mapping_path=None, output=None, category_search=None, afte
 | 
			
		||||
        except KeyError:
 | 
			
		||||
            if show_missing:
 | 
			
		||||
                output_writer.writerow([fact[6], fact[5]])
 | 
			
		||||
            click.secho("Can't find mapping for '{0}', skipping".format(k), fg='yellow')
 | 
			
		||||
            click.secho(
 | 
			
		||||
                "Can't find mapping for '{0}', skipping".format(k), fg='yellow')
 | 
			
		||||
            continue
 | 
			
		||||
 | 
			
		||||
        if show_missing:
 | 
			
		||||
@ -611,18 +631,18 @@ def _import(username, mapping_path=None, output=None, category_search=None, afte
 | 
			
		||||
        output_writer.writerow([
 | 
			
		||||
            date_start.strftime('%Y-%m-%d'),
 | 
			
		||||
            date_start.strftime('%H:%M'),
 | 
			
		||||
            '', # To (time)
 | 
			
		||||
            '',  # To (time)
 | 
			
		||||
            duration,
 | 
			
		||||
            '', # Rate
 | 
			
		||||
            '',  # Rate
 | 
			
		||||
            username,
 | 
			
		||||
            mapping_[0],
 | 
			
		||||
            mapping_[1],
 | 
			
		||||
            mapping_[2],
 | 
			
		||||
            fact[3] or '',
 | 
			
		||||
            '0', # Exported
 | 
			
		||||
            '0',  # Exported
 | 
			
		||||
            mapping_[3],
 | 
			
		||||
            '', # Hourly rate
 | 
			
		||||
            '', # Fixed rate
 | 
			
		||||
            '',  # Hourly rate
 | 
			
		||||
            '',  # Fixed rate
 | 
			
		||||
        ])
 | 
			
		||||
 | 
			
		||||
    output_file.close()
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user