diff --git a/.gitignore b/.gitignore index 51cbe85..8e6922c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +apikey.py # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/apikey.py.example b/apikey.py.example new file mode 100644 index 0000000..3eeb01a --- /dev/null +++ b/apikey.py.example @@ -0,0 +1,2 @@ +API_EMAIL='myemail@example.org' +API_KEY='myalphanumericapikey' diff --git a/updater.py b/updater.py index 6f2c7e9..44ef84c 100644 --- a/updater.py +++ b/updater.py @@ -3,17 +3,14 @@ from dnsimple import DNSimple from urllib import urlopen from sys import stderr, exit +from apikey import API_EMAIL, API_KEY domains = [{"domain": 'jshaver.net', "names": ["", "bc"]}, {"domain": 'theamazingshavers.com', "names": [""]}] -token = "esnmgLubCqZkRKiNsbwVQ" - -email = "bobjohnbob@gmail.com" - ttl = 600 -dns = DNSimple(email=email, api_token = token) +dns = DNSimple(email=API_EMAIL, api_token=API_KEY) response = urlopen("http://icanhazip.com/") @@ -25,22 +22,25 @@ ip = response.readline().rstrip() def get_a_record(domain, name): records = dns.records(domain) - for record in records: + for entry in records: + record = entry["record"] if record["name"] is name and ["record_type"] is 'A': return record return None def update_record(domain, name, record, ip): - new = {"record": {"name": name, "content": ip}} + new = {"name": name, "content": ip} response = dns.update_record(domain, record["id"], new) return response["record"] def create_record(domain, name, ip): - new = {"record": { + new = { "name": name, - "content",: ip, + "content": ip, "record_type": "A", - "ttl": ttl}} + "ttl": ttl} + print new + print domain response = dns.add_record(domain, new) return response["record"] @@ -58,7 +58,7 @@ def update_domain_ip(domain, name, ip): def main(domainList, ip): for domain in domainList: for name in domain["names"]: - update_domain_ip(domain, name, ip) + update_domain_ip(domain["domain"], name, ip) main(domains, ip)