From 1c36b0ce4ceb93e8618cc72fe80e4a3512704b6d Mon Sep 17 00:00:00 2001 From: Jannik Steinbach <jannikac@mailbox.org> Date: Thu, 14 Dec 2017 20:44:19 +0100 Subject: [PATCH] Ported to python3 and fixed indentation error --- gandi-ddns.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gandi-ddns.py b/gandi-ddns.py index 6bee504..12e0c34 100755 --- a/gandi-ddns.py +++ b/gandi-ddns.py @@ -1,4 +1,4 @@ -import ConfigParser as configparser +import configparser as configparser import sys import os import requests @@ -17,13 +17,13 @@ def get_ip(): except Exception: print('Failed to retrieve external IP.') sys.exit(2) - if r.status_code != 200: - print('Failed to retrieve external IP. Server responded with status_code: %d' % r.status_code) + if r.status_code != 200: + print(('Failed to retrieve external IP. Server responded with status_code: %d' % r.status_code)) sys.exit(2) ip = r.text.rstrip() # strip \n and any trailing whitespace - if not(ipaddress.IPv4Address(ip)): # check if valid IPv4 address + if not(ipaddress.IPv4Address(ip)): # check if valid IPv4 address sys.exit(2) return ip @@ -45,8 +45,8 @@ def update_record(url, headers, payload): #Add record r = requests.put(url, headers=headers, json=payload) if r.status_code != 201: - print('Record update failed with status code: %d' % r.status_code) - print(r.text) + print(('Record update failed with status code: %d' % r.status_code)) + print((r.text)) sys.exit(2) print ('Zone record updated.') @@ -62,7 +62,7 @@ def main(): sys.exit("Please fill in the 'config.txt' file.") for section in config.sections(): - + #Retrieve API key apikey = config.get(section, 'apikey') @@ -74,7 +74,7 @@ def main(): print(url) #Discover External IP external_ip = get_ip() - print('External IP is: %s' % external_ip) + print(('External IP is: %s' % external_ip)) #Prepare record payload = {'rrset_ttl': config.get(section, 'ttl'), 'rrset_values': [external_ip]} @@ -83,10 +83,10 @@ def main(): record = get_record(url, headers) if record.status_code == 200: - print('Current record value is: %s' % json.loads(record.text)['rrset_values'][0]) + print(('Current record value is: %s' % json.loads(record.text)['rrset_values'][0])) if(json.loads(record.text)['rrset_values'][0] == external_ip): print('No change in IP address. Goodbye.') - sys.exit() + continue else: print('No existing record. Adding...') -- GitLab