diff --git a/README.md b/README.md index 2d959ea6..0344e460 100644 --- a/README.md +++ b/README.md @@ -31,28 +31,13 @@ $ jc dig example.com | jq -r '.[].answer[].data' ``` The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary, or list of dictionaries, instead of JSON: ```python +>>> import subprocess >>> import jc.parsers.dig >>> ->>> data = '''; <<>> DiG 9.10.6 <<>> example.com -... ;; global options: +cmd -... ;; Got answer: -... ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64612 -... ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 -... -... ;; OPT PSEUDOSECTION: -... ; EDNS: version: 0, flags:; udp: 4096 -... ;; QUESTION SECTION: -... ;example.com. IN A -... -... ;; ANSWER SECTION: -... example.com. 29658 IN A 93.184.216.34 -... -... ;; Query time: 52 msec -... ;; SERVER: 2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1) -... ;; WHEN: Fri Apr 16 16:13:00 PDT 2021 -... ;; MSG SIZE rcvd: 56''' +>>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True) +>>> data = jc.parsers.dig.parse(cmd_output) >>> ->>> jc.parsers.dig.parse(data) +>>> data [{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', 'ra'], 'query_num': 1, 'answer_num': 1, 'authority_num': 0, 'additional_num': 1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp': 4096}}, 'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': [{'name': 'example.com.', diff --git a/templates/readme_template b/templates/readme_template index da09d75d..8466913a 100644 --- a/templates/readme_template +++ b/templates/readme_template @@ -31,28 +31,13 @@ $ jc dig example.com | jq -r '.[].answer[].data' ``` The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary, or list of dictionaries, instead of JSON: ```python +>>> import subprocess >>> import jc.parsers.dig >>> ->>> data = '''; <<>> DiG 9.10.6 <<>> example.com -... ;; global options: +cmd -... ;; Got answer: -... ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64612 -... ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 -... -... ;; OPT PSEUDOSECTION: -... ; EDNS: version: 0, flags:; udp: 4096 -... ;; QUESTION SECTION: -... ;example.com. IN A -... -... ;; ANSWER SECTION: -... example.com. 29658 IN A 93.184.216.34 -... -... ;; Query time: 52 msec -... ;; SERVER: 2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1) -... ;; WHEN: Fri Apr 16 16:13:00 PDT 2021 -... ;; MSG SIZE rcvd: 56''' +>>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True) +>>> data = jc.parsers.dig.parse(cmd_output) >>> ->>> jc.parsers.dig.parse(data) +>>> data [{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', 'ra'], 'query_num': 1, 'answer_num': 1, 'authority_num': 0, 'additional_num': 1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp': 4096}}, 'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': [{'name': 'example.com.',