Skip to content

Commit

Permalink
Fix coding style using black
Browse files Browse the repository at this point in the history
  • Loading branch information
jsphpl committed Apr 20, 2020
1 parent ada6825 commit b6933ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ License: Public Domain
Author: Joseph Paul <[email protected]>
positional arguments:
input_file Path to Enpass json export file
output_file Path to output file (csv)
input_file Path to Enpass JSON export file
output_file Path to output file (CSV)
optional arguments:
-h, --help show this help message and exit
Expand Down
41 changes: 24 additions & 17 deletions enpass-to-keepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import csv
import json

DIRECTLY_MAPPED_FIELDS = ['url', "username", 'password']
CSV_HEADERS = ["title", 'url', "username", 'password', "group", "notes"]
DIRECTLY_MAPPED_FIELDS = ["url", "username", "password"]
CSV_HEADERS = ["title", "url", "username", "password", "group", "notes"]
FIELD_ALIASES = {
'website': 'url',
'e-mail': 'email',
'login': 'username',
'benutzername': 'username',
'kennwort': 'password',
"website": "url",
"e-mail": "email",
"login": "username",
"benutzername": "username",
"kennwort": "password",
}

extra_keys = set([])
Expand Down Expand Up @@ -50,22 +50,24 @@ def process_item(item, folders):
if field_alias == "username":
username = field["value"]
else:
if field_alias == 'email':
if field_alias == "email":
email = field["value"]
continue

if len(str(field['value'])) > 0:
if len(str(field["value"])) > 0:
extra_fields[field["label"]] = field["value"]

extra_keys.add(field["label"])

if email:
if username:
extra_fields['E-mail'] = email
extra_fields["E-mail"] = email
else:
result["username"] = email

result['notes'] = '\n'.join([f'{key}: {value}' for key, value in extra_fields.items()])
result["notes"] = "\n".join(
[f"{key}: {value}" for key, value in extra_fields.items()]
)

return result

Expand Down Expand Up @@ -97,12 +99,17 @@ def convert_enpass_to_keypass(input_file, output_file):
writer.writerows(results)


if __name__ == '__main__':
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('input_file', type=argparse.FileType('r'),
help='Path to Enpass JSON export file')
parser.add_argument('output_file', type=argparse.FileType('w'),
help='Path to output file (CSV)')
description=__doc__, formatter_class=argparse.RawTextHelpFormatter
)
parser.add_argument(
"input_file",
type=argparse.FileType("r"),
help="Path to Enpass JSON export file",
)
parser.add_argument(
"output_file", type=argparse.FileType("w"), help="Path to output file (CSV)"
)
args = parser.parse_args()
convert_enpass_to_keypass(args.input_file, args.output_file)

0 comments on commit b6933ef

Please sign in to comment.