Created
May 8, 2019 05:58
-
-
Save saikpr/cbac7e9d2fb584c9fee0529f1dcba5a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 argparse | |
import io | |
import tqdm | |
import subprocess | |
from subprocess import DEVNULL | |
def main(lastpass_filename): | |
names = set() | |
with open(lastpass_filename) as fil: | |
reader = csv.DictReader(fil) | |
reader_list = list(reader) | |
for line in tqdm.tqdm(reader_list): | |
is_secure_note = False | |
name_list = [] | |
output_string_list = [] | |
if line["url"] == "http://sn": | |
name_list.append("SecureNotes") | |
is_secure_note = True | |
if len(line["grouping"].strip()) > 2: | |
name_list.append(line["grouping"].strip()) | |
name_list.append(line["name"]) | |
name_list.append(line["username"]) | |
name = "/".join(name_list) | |
if name in names: | |
print(name) | |
else: | |
names.add(name) | |
output_string_list.append(line["password"]) | |
output_string_list.append("---") | |
if len(line["name"]) > 0: | |
output_string_list.append(f"{line['name']}") | |
if len(line["username"]) > 0: | |
output_string_list.append(f'username: {line["username"]}') | |
if len(line["password"]) > 0: | |
output_string_list.append(f'password: {line["password"]}') | |
if len(line["url"]) > 0 and is_secure_note is False: | |
output_string_list.append(f'url: {line["url"]}') | |
if len(line["extra"]) > 0: | |
extra = line["extra"].strip() | |
output_string_list.append(f"\n\nNote:\n======\n{extra}\n======") | |
# if is_secure_note: | |
# print("\n".join(output_string_list)) | |
file_string = "\n".join(output_string_list) | |
pass_input = io.StringIO("\n".join(output_string_list)) | |
process = subprocess.Popen( | |
["pass", "insert", "-m", name], stdin=subprocess.PIPE, stdout=DEVNULL | |
) | |
process.communicate(input=file_string.encode()) | |
process.wait() | |
if process.returncode != 0: | |
print(f"error, {name}") | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--input", required=True, type=str) | |
args = parser.parse_args() | |
main(args.input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment