added time out for the script

This commit is contained in:
Stephen Cochrane 2020-10-12 22:41:25 +02:00
parent 2b57e64e4d
commit f5be2b0de2
1 changed files with 12 additions and 2 deletions

14
dns.py
View File

@ -2,7 +2,7 @@
# @Author skiqqy
import requests
import os
import json
import time
f = open("secret/godaddy_key", "r")
@ -39,7 +39,17 @@ domains = {
}
# Get current public ip
ip = os.popen('curl ifconfig.me').read()
# Max 60s then give up (1s per try + 1s sleep = 2s per iter => 30*2 =60
for i in range(30):
ip = os.popen('curl ifconfig.me --max-time 1').read()
if ip == "":
# We timed out
time.sleep(1)
else:
break
if ip == "":
exit(1) # We could not get our ip
# Construct the post data
for domain in domains: