-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
47 lines (33 loc) · 1.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sys
import json
import requests
def get_ip() -> str:
ip = requests.get("https://ifconfig.me").text
return ip
def update_record(public_key: str, secret_key: str, domain: str, record: dict) -> bool:
url = "https://api.godaddy.com/v1/domains/{}/records/{}/{}".format(domain, record["type"], record["name"])
header = {
"Authorization": "sso-key {}:{}".format(public_key, secret_key),
"Content-Type": "application/json",
"Host": "api.godaddy.com"
}
ip = get_ip()
data = '[{"data": "%s", "ttl": %s}]' % (ip, record["ttl"])
response = requests.put(url, data, headers=header)
if response.text:
print(response.text)
return True
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python main.py <config_file>")
sys.exit(1)
with open(sys.argv[1], "r") as f:
config = json.loads(f.read())
public_key = config["public_key"]
secret_key = config["secret_key"]
domain = config["domain"]
records = config["records"]
for record in records:
success = update_record(public_key, secret_key, domain, record)
if not success:
print("Failed record: " + str(record))