From 2511d6ae4d103bc132a6d8ea08a78bd3f112f5d9 Mon Sep 17 00:00:00 2001 From: Kristian Krsnik Date: Wed, 26 Jul 2023 22:31:05 +0200 Subject: [PATCH] used more elegant library features --- dyn_gandi/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dyn_gandi/main.py b/dyn_gandi/main.py index dd3b0ec..f3392eb 100644 --- a/dyn_gandi/main.py +++ b/dyn_gandi/main.py @@ -27,7 +27,7 @@ def log(logline: str, path: str = './log.txt') -> None: # Go through resolvers until one retuns an IP def getCurrentIP(resolvers: list[str], log: callable) -> None | str: for resolver in resolvers: - response = requests.request('GET', resolver) + response = requests.get(resolver) if response.status_code == 200: current_ip = response.text.strip() is_ipv4 = re.search('^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\\b){4}$', current_ip) is not None @@ -47,11 +47,11 @@ def checkRecords(api: dict, current_ip: str, log: callable) -> dict: for key, domains in api.items(): headers = { 'authorization': f"Apikey {key}" } for domain, records in domains.items(): - response = requests.request('GET', f"https://api.gandi.net/v5/livedns/domains/{domain}/records?rrset_type=A", headers = headers) + response = requests.get(f"https://api.gandi.net/v5/livedns/domains/{domain}/records?rrset_type=A", headers = headers) if response.status_code == 200: - records_to_renew[key][domain] = list(set(records_to_renew[key][domain]) - set(record['rrset_name'] for record in (filter(lambda x: current_ip in x['rrset_values'], json.loads(response.text))))) + records_to_renew[key][domain] = list(set(records_to_renew[key][domain]) - set(record['rrset_name'] for record in (filter(lambda x: current_ip in x['rrset_values'], json.loads(response.json()))))) else: - log(f"[ERROR][{domain}][{response.status_code}] {response.text}") + log(f"[ERROR][{domain}][{response.status_code}] {response.json()}") return records_to_renew @@ -73,11 +73,11 @@ def renewRecords(records, current_ip, log, ttl = 3600): for domain, records in domains.items(): for record in records: - response = requests.request('PUT', f"https://api.gandi.net/v5/livedns/domains/{domain}/records/{record}", data = payload, headers = headers) + response = requests.put(f"https://api.gandi.net/v5/livedns/domains/{domain}/records/{record}", data = payload, headers = headers) if response.status_code == 201: log(f"[OK][{domain}][{record}] Renewed with IP '{current_ip}'") else: - log(f"[ERROR][{domain}][{record}][{response.status_code}] {response.text}") + log(f"[ERROR][{domain}][{record}][{response.status_code}] {response.json()}") def main(): settings = loadSettings()