diff --git a/dyn_gandi.py b/dyn_gandi.py index 3ad47c9..36d1eae 100644 --- a/dyn_gandi.py +++ b/dyn_gandi.py @@ -16,11 +16,11 @@ import json import os import sys -import re from configparser import ConfigParser from datetime import datetime import docopt as docpt +import tldextract from docopt import docopt from ip_resolver import IpResolver, IpResolverError @@ -189,12 +189,12 @@ def main(): domain = config['dns']['domain'] # type: str # Sub-domain check - domain = domain.replace(".co.uk", ".co_uk") - if re.match(r"^.+\.[^.]+\.[^.]+$", domain): + domain_ext = tldextract.extract(domain) + if domain_ext.subdomain: if verbose: print("Warning: removing sub-domain part of %s" % domain) - domain = re.sub(r"^.+\.([^.]+\.[^.]+)$", r"\g<1>", domain) - domain = domain.replace(".co_uk", ".co.uk") + + domain = f'{domain_ext.domain}.{domain_ext.suffix}' if verbose: print("Domain: %s" % domain) diff --git a/livedns_client.py b/livedns_client.py index ca11cb0..901ce73 100644 --- a/livedns_client.py +++ b/livedns_client.py @@ -37,6 +37,7 @@ def _query_api(self, method, query, json_data=None): url = "%s%s" % (self.url, urllib.parse.quote(query)) headers = { + "x-api-key": self.key, "Authorization": "Apikey %s" % self.key, "Accept": "application/json", } diff --git a/setup.py b/setup.py index 6764a44..1b80c4c 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ from setuptools import setup, find_packages requires = [ + 'tldextract', 'docopt', 'requests', ]