Skip to content

Instantly share code, notes, and snippets.

@nzbr
Created July 21, 2019 19:34
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 nzbr/baa54123e32225dd28205cfd0f43dd45 to your computer and use it in GitHub Desktop.
Save nzbr/baa54123e32225dd28205cfd0f43dd45 to your computer and use it in GitHub Desktop.
Creates a CSV export from a pass password-store (can be imported as a LastPass export, for example in Bitwarden)
#!/usr/bin/python3
import os
from sys import stdout, stderr
from subprocess import Popen, PIPE, DEVNULL
def eprint(text: str) -> None:
stderr.write(text+"\n")
stderr.flush()
store = []
eprint("Decrypting...")
for pathname, dirs, files in os.walk("."):
for filename in files:
if not filename[-4:] == ".gpg":
continue
fullname = os.path.join(pathname, filename)
pathparts = fullname.split("/")[1:]
entry = pathparts[:-1]+[pathparts[-1][:-4]]
decryptProcess=Popen(["gpg", "-d", fullname], stdout=PIPE, stderr=DEVNULL)
content=[line[:-1].decode("utf-8") for line in decryptProcess.stdout]
# Set defaults
url = ""
username=entry[-1]
name=entry[-2] if len(entry) >1 else entry[-1]
grouping="/".join(entry[:-2])
password=content[0]
extra=content[1:]
params = {}
for line in extra:
if not line.strip() == "":
splitline = line.split(":")
params[splitline[0].strip()] = ":".join(splitline[1:]).strip()
if "url" in params:
url = params.pop("url")
if "login" in params:
username = params.pop("login")
name = entry[-1]
grouping="/".join(entry[:-1])
# Make extra string
extra = ""
for k,v in params.items():
extra += k+": "+v+"\n"
extra=extra[:-1]
store += [[url, username, password, extra, name, grouping, "0"]]
eprint(fullname)
eprint("\nSorting...")
store.sort(key=lambda x: x[4])
eprint("Writing result to stdout")
print("url,username,password,extra,name,grouping,fav")
for i in range(0,len(store)):
entry = store[i].copy()
if (i > 0 and entry[4] == store[i-1][4]) or (i < len(store)-1 and entry[4] == store[i+1][4]):
entry[4] = entry[4] + " - " + entry[1]
print('"' + '","'.join(entry) + '"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment