1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-09 01:05:53 +02:00
This commit is contained in:
Kelly Brazil
2022-01-20 09:59:23 -08:00
parent a4e34b0053
commit 15addd9bfc
2 changed files with 4 additions and 8 deletions

View File

@ -7,10 +7,7 @@ jc - JSON CLI output utility universal Parsers
simple_table_parse(data) simple_table_parse(data)
``` ```
Parse simple tables. The last column may contain data with spaces Parse simple tables. The last column may contain data with spaces.
code adapted from Conor Heine at:
https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
Parameters: Parameters:

View File

@ -6,10 +6,7 @@ import string
def simple_table_parse(data): def simple_table_parse(data):
""" """
Parse simple tables. The last column may contain data with spaces Parse simple tables. The last column may contain data with spaces.
code adapted from Conor Heine at:
https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
Parameters: Parameters:
@ -26,6 +23,8 @@ def simple_table_parse(data):
List of Dictionaries List of Dictionaries
""" """
# code adapted from Conor Heine at:
# https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501
headers = [h for h in ' '.join(data[0].strip().split()).split() if h] headers = [h for h in ' '.join(data[0].strip().split()).split() if h]
raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), data[1:]) raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), data[1:])
raw_output = [dict(zip(headers, r)) for r in raw_data] raw_output = [dict(zip(headers, r)) for r in raw_data]