Skip to content

Commit

Permalink
fix updater
Browse files Browse the repository at this point in the history
- Update process was failing due to error in json format
- Add check for request error messege
  • Loading branch information
salaheldinaz committed Apr 21, 2019
1 parent d27a827 commit 382717b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
.idea/
ven/
.DS_Store
api_data.json

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
30 changes: 20 additions & 10 deletions classes/cf_api.py
Expand Up @@ -109,16 +109,26 @@ def update_dns(self, new_ip, current_ip, current_domain, record_type):
else:
print(ST.os("IP address changed,updating DNS " + record_type + " record"))
url = self.api_url + self.domain_token + "/dns_records/" + self.record_token
payload = {"type": record_type, "name": current_domain, "content": new_ip, "ttl": 1, "proxied": "false"}
requests.put(url, data=payload, headers=self.header)
print(ST.hd("Domain "
+ current_domain
+ " | ip address updated to "
+ new_ip + " | DNS record "
+ record_type))
update_status = "updated"
return update_status

payload = '{"type":"' + str(record_type) \
+ '","name":"' + str(current_domain) \
+ '","content":"' + str(new_ip) \
+ '","ttl":1,"proxied":true}'

response = requests.put(url, data=payload, headers=self.header)
done = json.loads(response.text)["success"]
if done is True:
print(ST.hd("Domain "
+ current_domain
+ " | ip address updated to "
+ new_ip + " | DNS record "
+ record_type))
update_status = "updated"
return update_status
else:
print("Domain update failed")
update_status = "failed"
return update_status
# logging
@staticmethod
def log_(update_status, current_ip, new_ip, current_domain):
Expand All @@ -132,7 +142,7 @@ def log_(update_status, current_ip, new_ip, current_domain):
+ update_status
+ ", ip: " + current_ip + " > " + new_ip
+ "\n")
elif update_status == "unchanged":
elif update_status == "unchanged" or "failed":
log_msg = str(current_domain
+ " | DNS record "
+ update_status
Expand Down

0 comments on commit 382717b

Please sign in to comment.