1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-12-13 23:56:37 +02:00

add history and uptime parsers

This commit is contained in:
Kelly Brazil
2019-10-24 17:09:32 -07:00
parent f101d881a1
commit 41cd489c34
5 changed files with 126 additions and 0 deletions

32
jc/parsers/history.py Normal file
View File

@@ -0,0 +1,32 @@
"""jc - JSON CLI output utility history Parser
Usage:
specify --history as the first argument if the piped input is coming from history
Example:
$ history | jc --history -p
{
"118": "sleep 100",
"119": "ls /bin",
"120": "echo \"hello\"",
"121": "docker images",
...
}
"""
def parse(data):
output = {}
linedata = data.splitlines()
# Clear any blank lines
cleandata = list(filter(None, linedata))
if cleandata:
for entry in cleandata:
parsed_line = entry.split(maxsplit=1)
output[parsed_line[0]] = parsed_line[1]
return output