From b1077dc4be3141622393c22b322732a1d477bd34 Mon Sep 17 00:00:00 2001 From: John Gaunt Date: Thu, 8 Sep 2022 20:15:21 -0400 Subject: [PATCH] added attachment loop search and save --- bitwardenBackup.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bitwardenBackup.py b/bitwardenBackup.py index 029c97c..bc2350f 100644 --- a/bitwardenBackup.py +++ b/bitwardenBackup.py @@ -470,6 +470,21 @@ if __name__ == "__main__": logger.debug("Exporting organization vault to JSON") logger.debug((subprocess.run([bitwarden_cli_executable, 'export', '--organizationid', '{}'.format(organization['id']), '--output', os.path.join(script_directory, 'Bitwarden Organziation {} Export {}.json'.format(organization['name'], datetime_string)), '--format', 'json'], capture_output=True).stdout).decode()) + logger.info("Looking for items with attachments") + bitwarden_items = json.loads(((subprocess.run([bitwarden_cli_executable, 'list', 'items'], capture_output=True)).stdout).decode()) + bitwarden_items_with_attachments = () + for item in bitwarden_items: + logger.debug("Working on item {} ({})".format(item['name'], item['id'])) + if "attachments" in item: + logger.debug("Found {} attachments".format(len(item['attachments']))) + attachment_folder_name = os.path.join(script_directory, "attachments", "{}".format(item['name'])) + for attachment in item['attachments']: + logger.debug("Downloading attachment ({}) with name {} to folder {}".format(attachment['id'], attachment['name'], attachment_folder_name)) + logger.debug((subprocess.run([bitwarden_cli_executable, 'get', 'attachment', attachment['id'], '--itemid', item['id'], '--output', os.path.join(attachment_folder_name, attachment['filename'])], capture_output=True).stdout).decode()) + + else: + logger.debug("Item has no attachments") +