-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathzone_records.py
executable file
·56 lines (39 loc) · 1.51 KB
/
zone_records.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
# This script assumes an account token.
#
# If all you have is a user token you can run this script, by passing email and password when creating the client
# like so:
# `client = Client(sandbox=True, email=<your_email>, password=<your_password>`
import sys
from auth_token import token
from dnsimple import Client
"""
Construct a client instance.
If you want to connect to production omit the sandbox option
"""
client = Client(sandbox=True, access_token=token)
"""
All calls to client pass through a service. In this case, `client.identity` is the identity service
`client.identity.whoami() is the method for retrieving the account details for your
current credentials via the DNSimple API.
"""
response = client.identity.whoami()
"""
The response object returned by any API method includes a `data` attribute.
Underneath that attribute is an attribute for each data object returned.
In this case, `account` provides access to the contained account object.
Here the account id is extracted for use in future calls:
"""
account_id = response.data.account.id
"""
dnsimple.client.zones.list_records is the method to list the records in a DNSimple zone.
In the example below we are iterating through all the zone records of a given domain.
"""
page = 1
while True:
response = client.zones.list_records(account_id, str(sys.argv[1]), page=page)
for record in response.data:
print(f'- {record.content} ({record.id})')
if page == response.pagination.total_pages:
break
page += 1