2022-01-25 17:07:47 -08:00
|
|
|
<a id="jc"></a>
|
2020-07-30 16:20:24 -07:00
|
|
|
|
2019-11-11 18:30:46 -08:00
|
|
|
# jc
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2019-11-11 18:30:46 -08:00
|
|
|
JC - JSON CLI output utility
|
|
|
|
|
|
|
|
* kellyjonbrazil@gmail.com
|
|
|
|
|
2022-01-21 16:13:00 -08:00
|
|
|
This package converts the output of many standard unix command line tools
|
|
|
|
and file-types to dictionaries and lists of dictionaries.
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-21 12:31:03 -08:00
|
|
|
## Interactive Documentation
|
2022-01-20 07:49:45 -08:00
|
|
|
|
2022-01-21 16:58:45 -08:00
|
|
|
>>> help('jc')
|
|
|
|
>>> help('jc.lib')
|
|
|
|
>>> help('jc.utils')
|
2022-01-20 07:49:45 -08:00
|
|
|
>>> jc.get_help('parser_module_name')
|
|
|
|
|
2022-01-21 12:31:03 -08:00
|
|
|
## Online Documentation
|
2022-01-20 07:49:45 -08:00
|
|
|
|
2022-01-21 14:08:19 -08:00
|
|
|
### Latest
|
2022-01-21 12:33:23 -08:00
|
|
|
|
2022-01-20 07:49:45 -08:00
|
|
|
https://github.com/kellyjonbrazil/jc/tree/master/docs
|
2020-08-11 06:36:30 -07:00
|
|
|
|
2022-01-21 12:41:52 -08:00
|
|
|
### Specific Version
|
|
|
|
|
|
|
|
Replace `{{full_version_number}}` - e.g. `1.17.7`:
|
2022-01-21 12:33:23 -08:00
|
|
|
|
2022-01-21 12:35:48 -08:00
|
|
|
`https://github.com/kellyjonbrazil/jc/tree/v{{full_version_number}}/docs`
|
2022-01-21 12:31:03 -08:00
|
|
|
|
2022-01-21 12:39:22 -08:00
|
|
|
Specific versions can also be selected by tag in the branch dropdown menu.
|
|
|
|
|
2022-01-21 14:08:19 -08:00
|
|
|
## Usage Example
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-18 13:40:09 -08:00
|
|
|
>>> import subprocess
|
|
|
|
>>> import jc
|
|
|
|
>>>
|
2022-01-19 10:31:46 -08:00
|
|
|
>>> cmd_output = subprocess.check_output(['dig', 'example.com'],
|
|
|
|
text=True)
|
2022-01-18 13:40:09 -08:00
|
|
|
>>> data = jc.parse('dig', cmd_output)
|
|
|
|
>>> data
|
2022-01-19 10:31:46 -08:00
|
|
|
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', ...}]
|
2022-01-18 13:40:09 -08:00
|
|
|
|
2022-01-19 10:31:46 -08:00
|
|
|
Alternatively, you can bypass the high-level API and call the parser
|
|
|
|
modules directly:
|
2022-01-18 13:40:09 -08:00
|
|
|
|
2021-09-10 14:27:50 -07:00
|
|
|
>>> import subprocess
|
|
|
|
>>> import jc.parsers.dig
|
|
|
|
>>>
|
2022-01-19 10:31:46 -08:00
|
|
|
>>> cmd_output = subprocess.check_output(['dig', 'example.com'],
|
|
|
|
text=True)
|
2021-09-10 14:27:50 -07:00
|
|
|
>>> data = jc.parsers.dig.parse(cmd_output)
|
|
|
|
>>> data
|
2022-01-19 10:31:46 -08:00
|
|
|
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', ...}]
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-21 12:31:03 -08:00
|
|
|
## Available Functions
|
|
|
|
|
|
|
|
Use `help(jc.lib)` for details:
|
2022-01-19 19:19:25 -08:00
|
|
|
|
2022-01-19 19:22:08 -08:00
|
|
|
parse(parser_module_name: str, data: str | iterable)
|
|
|
|
High-level API to easily access the parser. This API will find both
|
|
|
|
built-in parsers and local plugin parsers.
|
2022-01-19 19:19:25 -08:00
|
|
|
|
2022-01-19 19:22:08 -08:00
|
|
|
get_help(parser_module_name: str)
|
2022-01-19 19:27:46 -08:00
|
|
|
Convenience function to display the help screen for a parser using
|
|
|
|
its module name.
|
2022-01-19 19:19:25 -08:00
|
|
|
|
2022-01-19 19:22:08 -08:00
|
|
|
parser_mod_list()
|
2022-01-19 19:27:46 -08:00
|
|
|
Get a list of all available parser module names to be used in
|
|
|
|
parse() and get_help().
|
2022-01-19 19:19:25 -08:00
|
|
|
|
2022-01-19 19:22:08 -08:00
|
|
|
plugin_parser_mod_list()
|
|
|
|
Get a list of plugin parser module names. This list is a subset of
|
|
|
|
parser_mod_list().
|
2022-01-18 13:46:11 -08:00
|
|
|
|