mirror of
git://git.acid.vegas/IRCP.git
synced 2024-11-26 01:46:39 +00:00
Added the ability to search for strings with hilighting in the results using ANSI colors
This commit is contained in:
parent
36570ea341
commit
bc3ccac030
21
parser.py
21
parser.py
@ -5,12 +5,12 @@ import json
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def parse(data, raw=True):
|
def parse(option, data, raw=True):
|
||||||
if not raw:
|
if not raw:
|
||||||
data = ' '.join(line.split()[3:])
|
data = ' '.join(line.split()[3:])
|
||||||
if data[:1] == ':':
|
if data[:1] == ':':
|
||||||
data = data[1:]
|
data = data[1:]
|
||||||
print(data)
|
print(data.replace(option, f'\033[31m{option}\033[0m'))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
@ -24,7 +24,11 @@ if len(sys.argv) >= 2:
|
|||||||
found = list()
|
found = list()
|
||||||
for log in logs:
|
for log in logs:
|
||||||
with open('logs/'+log) as logfile:
|
with open('logs/'+log) as logfile:
|
||||||
data = json.loads(logfile.read())
|
try:
|
||||||
|
data = json.loads(logfile.read())
|
||||||
|
except:
|
||||||
|
print('error: failed to load ' + log)
|
||||||
|
break
|
||||||
if option in data:
|
if option in data:
|
||||||
data = data[option]
|
data = data[option]
|
||||||
if type(data) == str:
|
if type(data) == str:
|
||||||
@ -32,9 +36,18 @@ if len(sys.argv) >= 2:
|
|||||||
elif type(data) == list:
|
elif type(data) == list:
|
||||||
for item in data:
|
for item in data:
|
||||||
found.append(parse(item, raw))
|
found.append(parse(item, raw))
|
||||||
|
else:
|
||||||
|
for item in data:
|
||||||
|
_data = data[item]
|
||||||
|
if type(_data) == str and option in _data:
|
||||||
|
found.append(parse(option, item, raw))
|
||||||
|
elif type(_data) == list:
|
||||||
|
for _item in _data:
|
||||||
|
if option in _item:
|
||||||
|
found.append(parse(option, _item, raw))
|
||||||
if found:
|
if found:
|
||||||
print(f'\nfound {len(found)} results in {len(logs)} logs')
|
print(f'\nfound {len(found)} results in {len(logs)} logs')
|
||||||
else:
|
else:
|
||||||
print('usage: python parser.py <field> [clean]\n')
|
print('usage: python parser.py <field> [clean]\n')
|
||||||
print(' <field> may be any item in the snapshots (001, NOTICE, 464, etc)')
|
print(' <field> may be any item in the snapshots (001, NOTICE, 464, etc) or a string to search')
|
||||||
print(' [clean] may be optionally used to display a cleaner output')
|
print(' [clean] may be optionally used to display a cleaner output')
|
Loading…
Reference in New Issue
Block a user