Created
April 1, 2020 20:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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