11
11
zones, with proxying enabled or disabled. The tool runs checks and updates every
12
12
5 minutes and includes redundancy for IP checking services.
13
13
"""
14
+ # pylint: disable=line-too-long
14
15
15
16
import time
16
17
import socket
@@ -67,8 +68,8 @@ def create_logger(level=logging.INFO):
67
68
LOGGER = create_logger ()
68
69
69
70
70
- # Get current DNS record for the specified domain
71
71
def get_dns_record (zone_id , domain_name ):
72
+ """ Get current DNS record for the specified domain """
72
73
LOGGER .info ("Fetching record for '%s' in zone '%s'." , domain_name , zone_id )
73
74
74
75
headers = {
@@ -94,8 +95,8 @@ def get_dns_record(zone_id, domain_name):
94
95
return None
95
96
96
97
97
- # Update the DNS record
98
98
def update_dns_record (record , content ):
99
+ """ Update the DNS record """
99
100
headers = {
100
101
'Authorization' : 'Bearer ' + CF_API_TOKEN ,
101
102
'Content-Type' : 'application/json' ,
@@ -118,8 +119,8 @@ def update_dns_record(record, content):
118
119
LOGGER .error ("Failed to update DNS record: %s" , response .json ())
119
120
120
121
121
- # Loads static wishlist of domains in json format along with their metadata
122
122
def read_zones_from_file (json_file_path , zone_id ):
123
+ """ Loads static wishlist of domains in json format along with their metadata """
123
124
with open (json_file_path , 'r' , encoding = "utf-8" ) as file :
124
125
data = json .load (file )
125
126
@@ -137,8 +138,8 @@ def read_zones_from_file(json_file_path, zone_id):
137
138
return zones
138
139
139
140
140
- # Fetches all DNS records that were loaded from file
141
141
def get_dns_records_by_name (zones ):
142
+ """ Fetches all DNS records that were loaded from file """
142
143
records = []
143
144
144
145
LOGGER .info ("Trying to fetch records for %s zones." , len (zones ))
@@ -173,14 +174,14 @@ def get_dns_records_by_comment(zone_id, comment_key):
173
174
return records
174
175
LOGGER .warning ("Request was successful but no valid domains were found: %s" , response .json ())
175
176
return []
176
-
177
+
177
178
LOGGER .error ("Failed to get dns_records with comment key: %s" , response .json ())
178
179
179
180
return []
180
181
181
182
182
- # Get public IP address from the list of IP checking services
183
183
def get_public_ip ():
184
+ """ Get public IP address from the list of IP checking services """
184
185
for service in IP_CHECK_SERVICES :
185
186
try :
186
187
response = requests .get (service , timeout = 5 )
@@ -191,8 +192,8 @@ def get_public_ip():
191
192
return None
192
193
193
194
194
- # Check if there is an active internet connection
195
195
def is_connected ():
196
+ """ Check if there is an active internet connection """
196
197
try :
197
198
host = socket .gethostbyname ("www.cloudflare.com" )
198
199
socket .create_connection ((host , 80 ), 2 )
@@ -201,8 +202,8 @@ def is_connected():
201
202
LOGGER .error ("Socket error: %s" , exc )
202
203
return False
203
204
204
- # Function to run the check and update process
205
205
def check_and_update_dns ():
206
+ """ Function to run the check and update process """
206
207
LOGGER .info ("Run triggered by schedule." )
207
208
208
209
if not is_connected ():
0 commit comments