@@ -69,7 +69,7 @@ def create_logger(level=logging.INFO):
69
69
70
70
# Get current DNS record for the specified domain
71
71
def get_dns_record (zone_id , domain_name ):
72
- LOGGER .info (f "Fetching record for '%s' in zone '%s'." , domain_name , zone_id )
72
+ LOGGER .info ("Fetching record for '%s' in zone '%s'." , domain_name , zone_id )
73
73
74
74
headers = {
75
75
'Authorization' : 'Bearer ' + CF_API_TOKEN ,
@@ -86,10 +86,10 @@ def get_dns_record(zone_id, domain_name):
86
86
records = response .json ()['result' ]
87
87
88
88
if records :
89
- LOGGER .info (f "Successfully fetched data for '%s'." , domain_name )
89
+ LOGGER .info ("Successfully fetched data for '%s'." , domain_name )
90
90
return records [0 ]
91
91
else :
92
- LOGGER .error (f "Failed to fetch data for '%s'. Response: %s" , domain_name , response .json ())
92
+ LOGGER .error ("Failed to fetch data for '%s'. Response: %s" , domain_name , response .json ())
93
93
94
94
return None
95
95
@@ -113,9 +113,9 @@ def update_dns_record(record, content):
113
113
)
114
114
115
115
if response .status_code == 200 :
116
- LOGGER .info (f "DNS record updated successfully: %s (%s) -> %s" , record ['name' ], record ['type' ], content )
116
+ LOGGER .info ("DNS record updated successfully: %s (%s) -> %s" , record ['name' ], record ['type' ], content )
117
117
else :
118
- LOGGER .error (f "Failed to update DNS record: %s" , response .json ())
118
+ LOGGER .error ("Failed to update DNS record: %s" , response .json ())
119
119
120
120
121
121
# Loads static wishlist of domains in json format along with their metadata
@@ -132,7 +132,7 @@ def read_zones_from_file(json_file_path, zone_id):
132
132
for domain in zone ['domains' ]:
133
133
domain ['zone_id' ] = zone ['id' ]
134
134
135
- LOGGER .info (f "Sucessfully read zone %s." , zone )
135
+ LOGGER .info ("Sucessfully read zone %s." , zone )
136
136
137
137
return zones
138
138
@@ -141,7 +141,7 @@ def read_zones_from_file(json_file_path, zone_id):
141
141
def get_dns_records_by_name (zones ):
142
142
records = []
143
143
144
- LOGGER .info (f "Trying to fetch records for %s zones." , len (zones ))
144
+ LOGGER .info ("Trying to fetch records for %s zones." , len (zones ))
145
145
146
146
for zone in zones :
147
147
for domain in zone ['domains' ]:
@@ -164,17 +164,17 @@ def get_dns_records_by_comment(zone_id, comment_key):
164
164
'comment.contains' : comment_key ,
165
165
}
166
166
167
- LOGGER .info (f "Fetching DNS record with comment key: %s" , comment_key )
167
+ LOGGER .info ("Fetching DNS record with comment key: %s" , comment_key )
168
168
response = requests .get (f'{ BASE_URL } zones/{ zone_id } /dns_records' , headers = headers , params = params , timeout = 60 )
169
169
170
170
if response .status_code == 200 :
171
171
records = response .json ()['result' ]
172
172
if records and len (records ) > 0 :
173
173
return records
174
- LOGGER .warning (f "Request was successful but no valid domains were found: %s" , response .json ())
174
+ LOGGER .warning ("Request was successful but no valid domains were found: %s" , response .json ())
175
175
return []
176
- else :
177
- LOGGER .error (f "Failed to get dns_records with comment key: %s" , response .json ())
176
+
177
+ LOGGER .error ("Failed to get dns_records with comment key: %s" , response .json ())
178
178
179
179
return []
180
180
@@ -199,7 +199,6 @@ def is_connected():
199
199
return True
200
200
except socket .error as exc :
201
201
LOGGER .error ("Socket error: %s" , exc )
202
- pass
203
202
return False
204
203
205
204
# Function to run the check and update process
@@ -224,21 +223,21 @@ def check_and_update_dns():
224
223
domain_records = []
225
224
226
225
if DNS_RECORD_COMMENT_KEY is not None :
227
- LOGGER .info (f "Using DNS_RECORD_COMMENT_KEY='%s' to find DNS records to update." , DNS_RECORD_COMMENT_KEY )
226
+ LOGGER .info ("Using DNS_RECORD_COMMENT_KEY='%s' to find DNS records to update." , DNS_RECORD_COMMENT_KEY )
228
227
domain_records = get_dns_records_by_comment (CF_ZONE_ID , DNS_RECORD_COMMENT_KEY )
229
228
else :
230
- LOGGER .info (f "Using DOMAINS_FILE_PATH='%s' to find DNS records to update." , DOMAINS_FILE_PATH )
229
+ LOGGER .info ("Using DOMAINS_FILE_PATH='%s' to find DNS records to update." , DOMAINS_FILE_PATH )
231
230
domain_records = get_dns_records_by_name (read_zones_from_file (DOMAINS_FILE_PATH , CF_ZONE_ID ))
232
231
233
232
valid_domains = [x ['name' ] for x in domain_records if x is not None ]
234
- LOGGER .info (f "Found %s valid domains for update: [%s]" , len (valid_domains ), ',' .join (valid_domains ))
233
+ LOGGER .info ("Found %s valid domains for update: [%s]" , len (valid_domains ), ',' .join (valid_domains ))
235
234
236
235
if public_ip :
237
236
for record in domain_records :
238
237
domain_name = record ['name' ]
239
238
240
239
if record is None :
241
- LOGGER .error (f "DNS record for %s not found." , domain_name )
240
+ LOGGER .error ("DNS record for %s not found." , domain_name )
242
241
continue
243
242
244
243
if public_ip != record ['content' ]:
@@ -247,12 +246,12 @@ def check_and_update_dns():
247
246
public_ip
248
247
)
249
248
else :
250
- LOGGER .info (f "IP addresses are the same for %s. No update needed." , domain_name )
249
+ LOGGER .info ("IP addresses are the same for %s. No update needed." , domain_name )
251
250
else :
252
251
LOGGER .error ("Failed to retrieve public IP. Skipping check and update." )
253
252
254
253
255
- LOGGER .info (f "Schedule is set at %s minutes" , SCHEDULE_MINUTES )
254
+ LOGGER .info ("Schedule is set at %s minutes" , SCHEDULE_MINUTES )
256
255
257
256
# Schedule the check and update process to run every X minutes
258
257
schedule .every (SCHEDULE_MINUTES ).minutes .do (check_and_update_dns ).run ()
0 commit comments