fix: Catch errors fir no records returned via API
All checks were successful
Build Docker / Build Main Image (push) Successful in 20s
Build Docker / Build SLDs Image (push) Successful in 19s

This commit is contained in:
Nathan Woodburn 2023-11-16 15:11:54 +11:00
parent f49a14c5b2
commit 0ca9a8ac91
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

30
varo.py
View File

@ -67,10 +67,11 @@ def get_auth_id(domain):
} }
r = requests.post(url, headers=headers, json=data) r = requests.post(url, headers=headers, json=data)
r = r.json() r = r.json()
if 'data' not in r:
return ""
for record in r['data']: for record in r['data']:
if record['name'] == domain + "." + city_domain: if 'profile avatar=' not in record['content']:
if 'profile avatar=' not in record['content']: return record['uuid']
return record['uuid']
return "" return ""
def get_auth(domain): def get_auth(domain):
@ -91,10 +92,12 @@ def get_auth(domain):
} }
r = requests.post(url, headers=headers, json=data) r = requests.post(url, headers=headers, json=data)
r = r.json() r = r.json()
if 'data' not in r:
return ""
for record in r['data']: for record in r['data']:
if record['name'] == domain + "." + city_domain: if 'profile avatar=' not in record['content']:
if 'profile avatar=' not in record['content']: return record['content']
return record['content']
return "" return ""
def get_zone(): def get_zone():
@ -149,13 +152,14 @@ def update_avatar(avatar,domain):
r = requests.post(url, headers=headers, json=data) r = requests.post(url, headers=headers, json=data)
r = r.json() r = r.json()
record_id = "" record_id = ""
for record in r['data']: if 'data' in r:
if record['name'] == domain + "." + city_domain: for record in r['data']:
if 'profile avatar=' in record['content']: if record['name'] == domain + "." + city_domain:
if record['content'].split("profile avatar=")[1] == avatar: if 'profile avatar=' in record['content']:
print("Avatar already set", flush=True) if record['content'].split("profile avatar=")[1] == avatar:
return "Avatar already set" print("Avatar already set", flush=True)
record_id = record['uuid'] return "Avatar already set"
record_id = record['uuid']
if record_id == "": if record_id == "":
data = { data = {