Created
December 31, 2024 09:59
-
-
Save Askill/2c07c6f329b819a8f885589dbee54979 to your computer and use it in GitHub Desktop.
a short script to format a bitwarden export from json to a printable txt (ChatGPT, but tested)
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
import json | |
# Function to format notes for printable output | |
def format_notes(notes, width=50): | |
formatted_notes = "" | |
for i in range(0, len(notes), width): | |
formatted_notes += notes[i:i+width] + "\n" | |
return formatted_notes | |
# Read the Bitwarden JSON export and create a printable TXT file | |
def process_bitwarden_export(input_file, output_file): | |
try: | |
# Load JSON data | |
with open(input_file, 'r', encoding='utf-8') as file: | |
data = json.load(file) | |
# Open output file | |
with open(output_file, 'w', encoding='utf-8') as output: | |
# Iterate through items in the export | |
for item in data.get('items', []): | |
username = item.get('login', {}).get('username', 'N/A') | |
password = item.get('login', {}).get('password', 'N/A') | |
uri = item.get('login', {}).get('uris', [{}])[0].get('uri', 'N/A') if item.get('login', {}).get('uris') else 'N/A' | |
notes = item.get('notes', None) | |
# Write entry to the output file | |
output.write(f"Username: {username}\n") | |
output.write(f"Password: {password}\n") | |
output.write(f"URI: {uri}\n") | |
if notes: | |
output.write("Notes:\n") | |
output.write(format_notes(notes)) | |
output.write("-" * 50 + "\n") | |
print(f"Successfully created printable TXT file: {output_file}") | |
except Exception as e: | |
print(f"An error occurred: {e}") | |
input_file = "" # Replace with your input JSON file | |
output_file = "bitwarden_printable.txt" # Replace with your desired output TXT file | |
process_bitwarden_export(input_file, output_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment