Strip url
This commit is contained in:
parent
c53b64203d
commit
d68391cfc1
1 changed files with 13 additions and 7 deletions
20
pass2csv.py
20
pass2csv.py
|
@ -57,11 +57,13 @@ def set_data(entry, data, exclude, get_fields, get_lines):
|
||||||
|
|
||||||
matching_lines = {}
|
matching_lines = {}
|
||||||
for i, line in enumerate(filtered_tail):
|
for i, line in enumerate(filtered_tail):
|
||||||
for name, pattern in get_lines:
|
for name, pattern, subc in get_lines:
|
||||||
match = pattern.search(line)
|
match = pattern.search(line)
|
||||||
if not match:
|
if not match:
|
||||||
continue
|
continue
|
||||||
matches = matching_lines.setdefault(name, [])
|
matches = matching_lines.setdefault(name, [])
|
||||||
|
if subc is not None:
|
||||||
|
line = subc.sub('', line)
|
||||||
matches.append(line)
|
matches.append(line)
|
||||||
matching_indices.add(i)
|
matching_indices.add(i)
|
||||||
break
|
break
|
||||||
|
@ -284,14 +286,14 @@ def parse_args(args=None):
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-l', '--get-line',
|
'-l', '--get-line',
|
||||||
metavar=('name', 'pattern'),
|
metavar=('name', 'pattern', 'replace'),
|
||||||
action='append',
|
action='append',
|
||||||
nargs=2,
|
nargs=3,
|
||||||
type=str,
|
type=str,
|
||||||
default=[['otp', 'otpauth://'], ['url', 'https?://']],
|
default=[['otp', 'otpauth://', ''], ['url', 'https?://', '^url: *']],
|
||||||
help=(
|
help=(
|
||||||
"a name and a regexp for which all lines that match are included"
|
"a name and a regexp for which all lines that match are included"
|
||||||
" in a field with the chosen name"
|
" in a field with the chosen name. replace is a regex to remove matches of from entry."
|
||||||
),
|
),
|
||||||
dest='get_lines'
|
dest='get_lines'
|
||||||
)
|
)
|
||||||
|
@ -386,11 +388,15 @@ def cli():
|
||||||
get_fields.append((name, regexp))
|
get_fields.append((name, regexp))
|
||||||
|
|
||||||
get_lines = []
|
get_lines = []
|
||||||
for name, pattern in parsed.get_lines:
|
for name, pattern, subs in parsed.get_lines:
|
||||||
regexp = compile_regexp(pattern)
|
regexp = compile_regexp(pattern)
|
||||||
if not regexp:
|
if not regexp:
|
||||||
failed = True
|
failed = True
|
||||||
get_lines.append((name, regexp))
|
if subs == '':
|
||||||
|
subc = None
|
||||||
|
else:
|
||||||
|
subc = compile_regexp(subs)
|
||||||
|
get_lines.append((name, regexp, subc))
|
||||||
|
|
||||||
username_patterns = []
|
username_patterns = []
|
||||||
for pattern in parsed.usernames:
|
for pattern in parsed.usernames:
|
||||||
|
|
Loading…
Reference in a new issue