Skip to content

Commit b9fb6cc

Browse files
Update main.py to coding standard from pylint
1 parent 0debff2 commit b9fb6cc

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

main.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def create_logger(level=logging.INFO):
6969

7070
# Get current DNS record for the specified domain
7171
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)
7373

7474
headers = {
7575
'Authorization': 'Bearer ' + CF_API_TOKEN,
@@ -86,10 +86,10 @@ def get_dns_record(zone_id, domain_name):
8686
records = response.json()['result']
8787

8888
if records:
89-
LOGGER.info(f"Successfully fetched data for '%s'.", domain_name)
89+
LOGGER.info("Successfully fetched data for '%s'.", domain_name)
9090
return records[0]
9191
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())
9393

9494
return None
9595

@@ -113,9 +113,9 @@ def update_dns_record(record, content):
113113
)
114114

115115
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)
117117
else:
118-
LOGGER.error(f"Failed to update DNS record: %s", response.json())
118+
LOGGER.error("Failed to update DNS record: %s", response.json())
119119

120120

121121
# 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):
132132
for domain in zone['domains']:
133133
domain['zone_id'] = zone['id']
134134

135-
LOGGER.info(f"Sucessfully read zone %s.", zone)
135+
LOGGER.info("Sucessfully read zone %s.", zone)
136136

137137
return zones
138138

@@ -141,7 +141,7 @@ def read_zones_from_file(json_file_path, zone_id):
141141
def get_dns_records_by_name(zones):
142142
records = []
143143

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))
145145

146146
for zone in zones:
147147
for domain in zone['domains']:
@@ -164,17 +164,17 @@ def get_dns_records_by_comment(zone_id, comment_key):
164164
'comment.contains': comment_key,
165165
}
166166

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)
168168
response = requests.get(f'{BASE_URL}zones/{zone_id}/dns_records', headers=headers, params=params, timeout=60)
169169

170170
if response.status_code == 200:
171171
records = response.json()['result']
172172
if records and len(records) > 0:
173173
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())
175175
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())
178178

179179
return []
180180

@@ -199,7 +199,6 @@ def is_connected():
199199
return True
200200
except socket.error as exc:
201201
LOGGER.error("Socket error: %s", exc)
202-
pass
203202
return False
204203

205204
# Function to run the check and update process
@@ -224,21 +223,21 @@ def check_and_update_dns():
224223
domain_records = []
225224

226225
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)
228227
domain_records = get_dns_records_by_comment(CF_ZONE_ID, DNS_RECORD_COMMENT_KEY)
229228
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)
231230
domain_records = get_dns_records_by_name(read_zones_from_file(DOMAINS_FILE_PATH, CF_ZONE_ID))
232231

233232
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))
235234

236235
if public_ip:
237236
for record in domain_records:
238237
domain_name = record['name']
239238

240239
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)
242241
continue
243242

244243
if public_ip != record['content']:
@@ -247,12 +246,12 @@ def check_and_update_dns():
247246
public_ip
248247
)
249248
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)
251250
else:
252251
LOGGER.error("Failed to retrieve public IP. Skipping check and update.")
253252

254253

255-
LOGGER.info(f"Schedule is set at %s minutes", SCHEDULE_MINUTES)
254+
LOGGER.info("Schedule is set at %s minutes", SCHEDULE_MINUTES)
256255

257256
# Schedule the check and update process to run every X minutes
258257
schedule.every(SCHEDULE_MINUTES).minutes.do(check_and_update_dns).run()

0 commit comments

Comments
 (0)