From 80bd7801feb994a5ccf1ab315b6c3b6008627dbd Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Sun, 28 Feb 2021 23:58:11 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=B5=20Reduced=20duplicate=20logs=20[yo?= =?UTF-8?q?ur=20SD=20card(s)=20will=20thank=20me]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloudflare-ddns.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cloudflare-ddns.py b/cloudflare-ddns.py index 4b479c7..40920b6 100755 --- a/cloudflare-ddns.py +++ b/cloudflare-ddns.py @@ -2,6 +2,8 @@ import requests, json, sys, signal, os, time PATH = os.getcwd() + "/" version = float(str(sys.version_info[0]) + "." + str(sys.version_info[1])) +shown_ipv4_warning = False +shown_ipv6_warning = False if(version < 3.5): raise Exception("This script requires Python 3.5+") @@ -36,9 +38,9 @@ def deleteEntries(type): identifier = str(r["id"]) response = cf_api( "zones/" + c['zone_id'] + "/dns_records/" + identifier, "DELETE", c) - print("Deleted stale record " + identifier) + print("🗑️ Deleted stale record " + identifier) except Exception: - print("Error deleting " + type + " record(s)") + print("😡 Error deleting " + type + " record(s)") def getIPs(): a = None @@ -48,14 +50,18 @@ def getIPs(): a.pop() a = dict(s.split("=") for s in a)["ip"] except Exception: - print("⚠️ Warning: IPv4 not detected.") + if not shown_ipv4_warning: + shown_ipv4_warning = True + print("😨 Warning: IPv4 not detected.") deleteEntries("A") try: aaaa = requests.get("https://[2606:4700:4700::1111]/cdn-cgi/trace").text.split("\n") aaaa.pop() aaaa = dict(s.split("=") for s in aaaa)["ip"] except Exception: - print("⚠️ Warning: IPv6 not detected.") + if not shown_ipv6_warning: + shown_ipv6_warning = True + print("😨 Warning: IPv6 not detected.") deleteEntries("AAAA") ips = [] if(a is not None):