Skip to content

Instantly share code, notes, and snippets.

@ignlg
Created April 1, 2020 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ignlg/e5045d5fd90be0a9c990e54736f57b49 to your computer and use it in GitHub Desktop.
Save ignlg/e5045d5fd90be0a9c990e54736f57b49 to your computer and use it in GitHub Desktop.
Creates new KeePass entries as references to original entries when the URL is a list of URLs
from pykeepass import PyKeePass
def clean_url(url):
url_parts = url.split("/")
if url_parts[0] == "http:" or url_parts[0] == "https:":
return url_parts[2]
else:
return url
# load database
kp = PyKeePass('Example.kbdx', password='')
for group in kp.groups:
for entry in group.entries:
if entry.url != None:
if "," in entry.url:
urls = entry.url.split(",")
found = []
for i, url in enumerate(urls):
url_clean = clean_url(url)
if url_clean not in found:
found.append(url_clean)
if i == 0:
entry.url = url_clean
elif i > 0:
kp.add_entry(
group, entry.title + ' clone ' + str(i), '{REF:U@I:' + entry.uuid.hex + '}', '{REF:P@I:' + entry.uuid.hex + '}', url_clean)
else:
entry.url = clean_url(entry.url)
# save database
kp.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment