Improving "parse" mode for extracting usernames and other info for a further search

This commit is contained in:
Soxoj
2021-03-21 18:34:57 +03:00
parent e90e85d2a9
commit a2ddb15f09
6 changed files with 72 additions and 29 deletions
+21
View File
@@ -55,3 +55,24 @@ class URLMatcher:
regexp_str = self._HTTP_URL_RE_STR.replace('(.+)', url_regexp)
return re.compile(regexp_str)
def get_dict_ascii_tree(items, prepend='', new_line=True):
text = ''
for num, item in enumerate(items):
box_symbol = '┣╸' if num != len(items) - 1 else '┗╸'
if type(item) == tuple:
field_name, field_value = item
if field_value.startswith('[\''):
is_last_item = num == len(items) - 1
prepend_symbols = ' ' * 3 if is_last_item else ''
field_value = print_ascii_tree(eval(field_value), prepend_symbols)
text += f'\n{prepend}{box_symbol}{field_name}: {field_value}'
else:
text += f'\n{prepend}{box_symbol} {item}'
if not new_line:
text = text[1:]
return text