Created
August 27, 2021 23:56
-
-
Save yunruse/bc9def3f953823ff1e4d112714116661 to your computer and use it in GitHub Desktop.
Quick script to turn Bitwarden exported CSVs to iCloud CSVs with basic config
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 csv | |
import sys | |
from urllib.parse import urlparse | |
from argparse import ArgumentParser | |
parser = ArgumentParser() | |
parser.add_argument("input") | |
parser.add_argument("output") | |
parser.add_argument( | |
"--format-name", "-n", action="store_true", | |
help="Format names to 'url (username)'") | |
parser.add_argument( | |
"--strip-path", "-p", action="store_true", | |
help="Remove paths from URLs, keeping only the domain and subdomain.") | |
def pipe(file_input, file_output, args): | |
fieldnames = "Title,Url,Username,Password,OTPAuth".split(",") | |
writer = csv.DictWriter(file_output, fieldnames=fieldnames) | |
writer.writeheader() | |
for i, line in enumerate(csv.DictReader(file_input)): | |
if i == 0: | |
continue | |
# the query ?foo=bar is removed | |
uri = urlparse(line['login_uri']) | |
url = uri.scheme + "://" + uri.netloc | |
if not args.strip_path: | |
url += uri.path | |
username = line['login_username'] | |
writer.writerow({ | |
"Title": ( | |
f"{url} ({username})" if args.format_name | |
else line['name']), | |
"Url": url, | |
"Username": username, | |
"Password": line['login_password'], | |
"OTPAuth": line['login_totp'], | |
}) | |
if __name__ == '__main__': | |
args = parser.parse_args() | |
with open(args.input) as i: | |
with open(args.output, "w") as o: | |
pipe(i, o, args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment