Skip to content

Instantly share code, notes, and snippets.

@foxundermoon
Created March 29, 2018 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxundermoon/73280b1e36ade6cb5463cf2f63700e05 to your computer and use it in GitHub Desktop.
Save foxundermoon/73280b1e36ade6cb5463cf2f63700e05 to your computer and use it in GitHub Desktop.
dnspod list domain console output
payload = self._post(
'/Record.List', {'domain': self.options['domain']})
logger.debug('payload: %s', json.dumps(payload))
records = []
for record in payload['records']:
processed_record = {
'type': record['type'],
'name': self._full_name(record['name']),
'ttl': record['ttl'],
'content': record['value'],
# this id is useless unless your doing record linking. Lets
# return the original record identifier.
'id': record['id']
}
records.append(processed_record)
maxLengths = {}
keys = ['name', 'content', 'type', 'ttl', 'id']
newRecords = []
header = {}
for k in keys:
header[k] = k
newRecords.append(header)
for r in records:
newRecords.append(r)
for k in keys:
for r in newRecords:
maxLengths[k] = max(maxLengths.get(k, 0), len(r[k]))
fixRecors = []
for r in newRecords:
newRecord = {}
for k in keys:
newRecord[k] = r[k] + ' ' * (maxLengths[k] - len(r[k]))
fixRecors.append(newRecord)
for r in fixRecors:
values = []
for k in keys:
values.append(r[k])
print('\t'.join(values))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment