コード例 #1
0
def _import(params, format, filename):
    api.login(params)

    if format == 'json':
        def read_json():
            with open(filename, mode="rt", encoding="utf8") as f:
                return json.load(f)

        records_to_add = [api.prepare_record(params, parse_record_json(json)) for json in read_json()]
    else:
        def read_lines():
            with open(filename, mode="rt", encoding="utf8") as f:
                return f.readlines()

        records_to_add = [api.prepare_record(params, parse_line(line)) for line in read_lines()]

    if (len(records_to_add) == 0):
        print('No records to import')
        return

    request = api.make_request(params, 'record_update')
    print('importing {0} records to Keeper'.format(len(records_to_add)))
    request['add_records'] = records_to_add
    response_json = api.communicate(params, request)
    success = [info for info in response_json['add_records'] if info['status'] == 'success']
    if len(success) > 0:
        print("{0} records imported successfully".format(len(success)))
    failures = [info for info in response_json['add_records'] if info['status'] != 'success']
    if len(failures) > 0:
        print("{0} records failed to import".format(len(failures)))
コード例 #2
0
ファイル: imp_exp.py プロジェクト: m-wells/Commander
def _import(params, format, filename):
    api.login(params)

    if format == 'json':
        def read_json():
            with open(filename, 'rt') as f:
                return json.load(f)

        records_to_add = [api.prepare_record(params, parse_json(json)) for json in read_json()]
    else:
        def read_lines():
            with open(filename, 'rt') as f:
                return f.readlines()

        records_to_add = [api.prepare_record(params, parse_line(line)) for line in read_lines()]

    if (len(records_to_add) == 0):
        print('No records to import')
        return

    request = api.make_request(params, 'record_update')
    print('importing {0} records to Keeper'.format(len(records_to_add)))
    request['add_records'] = records_to_add
    response_json = api.communicate(params, request)
    success = [info for info in response_json['add_records'] if info['status'] == 'success']
    if len(success) > 0:
        print("{0} records imported successfully".format(len(success)))
    failures = [info for info in response_json['add_records'] if info['status'] != 'success']
    if len(failures) > 0:
        print("{0} records failed to import".format(len(failures)))
コード例 #3
0
ファイル: imp_exp.py プロジェクト: marcteale/Commander
def create_sf(params, filename):
    api.sync_down(params)

    def read_json():
        with open(filename, mode="rt", encoding="utf8") as f:
            return json.load(f)

    print('Creating shared folder(s)...')
    num_success = 0

    for json_sf in read_json():
        print('Preparing shared folder')
        my_shared_folder = api.prepare_shared_folder(params,
                                                     parse_sf_json(json_sf))
        request = api.make_request(params, 'shared_folder_update')

        request.update(my_shared_folder)

        if params.debug: print('Sending request')
        response_json = api.communicate(params, request)

        user_success = [
            info for info in response_json['add_users']
            if info['status'] == 'success'
        ]
        if len(user_success) > 0:
            print("{0} users added successfully".format(len(user_success)))

        user_failures = [
            info for info in response_json['add_users']
            if info['status'] != 'success'
        ]
        if len(user_failures) > 0:
            print("{0} users failed to get added".format(len(user_failures)))

        add_records_success = [
            info for info in response_json['add_records']
            if info['status'] == 'success'
        ]
        if len(add_records_success) > 0:
            print("{0} records added successfully".format(
                len(add_records_success)))

        add_records_failures = [
            info for info in response_json['add_records']
            if info['status'] != 'success'
        ]
        if len(add_records_failures) > 0:
            print("{0} records failed to get added".format(
                len(add_records_failures)))

        if len(user_success) + len(add_records_success) > 0:
            num_success += 1
            print('Created shared folder ' + request['shared_folder_uid'] +
                  'with success')

    if num_success > 0:
        print('Successfully created [' + str(num_success) + '] shared folders')
コード例 #4
0
def delete_all(params):
    api.sync_down(params)
    if (len(params.record_cache) == 0):
        print('No records to delete')
        return
    request = api.make_request(params, 'record_update')
    print('removing {0} records from Keeper'.format(len(params.record_cache)))
    request['delete_records'] = [key for key in params.record_cache.keys()]
    response_json = api.communicate(params, request)
    success = [info for info in response_json['delete_records'] if info['status'] == 'success']
    if len(success) > 0:
        print("{0} records deleted successfully".format(len(success)))
    failures = [info for info in response_json['delete_records'] if info['status'] != 'success']
    if len(failures) > 0:
        print("{0} records failed to delete".format(len(failures)))
コード例 #5
0
ファイル: imp_exp.py プロジェクト: m-wells/Commander
def delete_all(params):
    api.sync_down(params)
    if (len(params.record_cache) == 0):
        print('No records to delete')
        return
    request = api.make_request(params, 'record_update')
    print('removing {0} records from Keeper'.format(len(params.record_cache)))
    request['delete_records'] = [key for key in params.record_cache.keys()]
    response_json = api.communicate(params, request)
    success = [info for info in response_json['delete_records'] if info['status'] == 'success']
    if len(success) > 0:
        print("{0} records deleted successfully".format(len(success)))
    failures = [info for info in response_json['delete_records'] if info['status'] != 'success']
    if len(failures) > 0:
        print("{0} records failed to delete".format(len(failures)))