From 0ca9a8ac91ceab296df8812f81e4b55d50bb4689 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 16 Nov 2023 15:11:54 +1100 Subject: [PATCH] fix: Catch errors fir no records returned via API --- varo.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/varo.py b/varo.py index 8b8c1ad..e6c87fc 100644 --- a/varo.py +++ b/varo.py @@ -67,10 +67,11 @@ def get_auth_id(domain): } r = requests.post(url, headers=headers, json=data) r = r.json() + if 'data' not in r: + return "" for record in r['data']: - if record['name'] == domain + "." + city_domain: - if 'profile avatar=' not in record['content']: - return record['uuid'] + if 'profile avatar=' not in record['content']: + return record['uuid'] return "" def get_auth(domain): @@ -91,10 +92,12 @@ def get_auth(domain): } r = requests.post(url, headers=headers, json=data) r = r.json() + if 'data' not in r: + return "" + for record in r['data']: - if record['name'] == domain + "." + city_domain: - if 'profile avatar=' not in record['content']: - return record['content'] + if 'profile avatar=' not in record['content']: + return record['content'] return "" def get_zone(): @@ -149,13 +152,14 @@ def update_avatar(avatar,domain): r = requests.post(url, headers=headers, json=data) r = r.json() record_id = "" - for record in r['data']: - if record['name'] == domain + "." + city_domain: - if 'profile avatar=' in record['content']: - if record['content'].split("profile avatar=")[1] == avatar: - print("Avatar already set", flush=True) - return "Avatar already set" - record_id = record['uuid'] + if 'data' in r: + for record in r['data']: + if record['name'] == domain + "." + city_domain: + if 'profile avatar=' in record['content']: + if record['content'].split("profile avatar=")[1] == avatar: + print("Avatar already set", flush=True) + return "Avatar already set" + record_id = record['uuid'] if record_id == "": data = {