예제 #1
0
print(new_entries)         

def entries_equal(a, b):
    return (a['title'] == b['title'] and 
        a['username'] == b['username'] and
        a['password'] == b['password'] and
        a['notes'] == b['notes'])

# Read in the existing secrets file, then look for duplicates.
s = Secrets(secrets_file, keyphrase)
s.read()
entries = s.entries()
dupe_count = 0
add_count = 0
for new_entry in new_entries:
    for entry in entries:
        if entries_equal(entry, new_entry):
            # Entry already exists, avoid adding a duplicate
            dupe_count += 1
            break
    else:
        # All secrets searched, no duplicates found.
        # Add to secrets.
        s.add_entry(new_entry)
        add_count += 1
s.write()

print('{} merged, {} entries, {} were duplicate, {} added as new'.format(
        import_file, len(new_entries), dupe_count, add_count))

예제 #2
0
    'Title': 'title',
    'Username': '******',
    'Password': '******',
    'URL': 'url',
    'Notes': 'notes'
}

# Map csv fields to a column number in the source csv
mapping2 = {}
for k in mapping.keys():
    mapping2[k] = headers.index(k)

# Copy the data into our format
new_entries = []
for row in entries:
    new_entry = {}
    for k in mapping:
        if mapping[k] != None:
            new_entry[mapping[k]] = row[mapping2[k]]
    new_entries.append(new_entry)

print(new_entries)

s = Secrets(out_file, keyphrase)
s.new_vault()
for entry in new_entries:
    s.add_entry(entry)
s.write()
print('{} read and exported to {}, {} entries'.format(in_file, out_file,
                                                      len(new_entries)))