Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
cleaned up string response for /zones/:id/dns_records/export API call
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Oct 31, 2017
1 parent a25a4a9 commit 378dede
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ $
The following is documented within the **Advanced** option of the DNS page within the Cloudflare portal.

```
$ python -m cli4 /zones/:example.com/dns_records/export | jq -r . | egrep -v '^;;|^$'
$ python -m cli4 /zones/:example.com/dns_records/export | egrep -v '^;;|^$'
$ORIGIN .
@ 3600 IN SOA example.com. root.example.com. (
2025552311 ; serial
Expand All @@ -730,7 +730,7 @@ record2.example.com. 300 IN AAAA 2001:d8b::2
$
```

The **jq -r** option is used to convert newlines and tabs within the JSON response data. The egrep is used for documentation brevity.
The egrep is used for documentation brevity.

This can also be done via Python code with the following example.
```
Expand Down
7 changes: 3 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ page within the Cloudflare portal.

::

$ python -m cli4 /zones/:example.com/dns_records/export | jq -r . | egrep -v '^;;|^$'
$ python -m cli4 /zones/:example.com/dns_records/export | egrep -v '^;;|^$'
$ORIGIN .
@ 3600 IN SOA example.com. root.example.com. (
2025552311 ; serial
Expand All @@ -804,8 +804,7 @@ page within the Cloudflare portal.
record2.example.com. 300 IN AAAA 2001:d8b::2
$

The **jq -r** option is used to convert newlines and tabs within the
JSON response data. The egrep is used for documentation brevity.
The egrep is used for documentation brevity.

This can also be done via Python code with the following example.

Expand Down Expand Up @@ -1035,7 +1034,7 @@ and/or
Python 2.x vs 3.x support
-------------------------

As of May/June 2016 the code is now tested againt pylint. This was
As of May/June 2016 the code is now tested against pylint. This was
required in order to move the codebase into Python 3.x. The motivation
for this came from `Danielle Madeley
(danni) <https://github.com/danni>`__.
Expand Down
18 changes: 12 additions & 6 deletions cli4/cli4.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,16 @@ def cli4(args):
if len(results) == 1:
results = results[0]

if output == 'json':
sys.stdout.write(json.dumps(results, indent=4, sort_keys=True) + '\n')
# json.dumps(results, sys.stdout, indent=4, sort_keys=True)
# sys.stdout.write('\n')
if output == 'yaml':
sys.stdout.write(yaml.safe_dump(results))
if isinstance(results, str):
# if the results are a simple string, then it should be dumped directly
# this is only used for /zones/:id/dns_records/export presently
sys.stdout.write(results)
else:
# anything more complex (dict, list, etc) should be dumped as JSON/YAML
if output == 'json':
sys.stdout.write(json.dumps(results, indent=4, sort_keys=True) + '\n')
# json.dumps(results, sys.stdout, indent=4, sort_keys=True)
# sys.stdout.write('\n')
if output == 'yaml':
sys.stdout.write(yaml.safe_dump(results))

0 comments on commit 378dede

Please sign in to comment.