Hey y’all - I’m very new to coding and starlark and all that. I want to push an app to my brand new Tidbyt to show current status of my small ubiquity UISP network. Anyone have a chance to maybe look at my code and have an idea of how this would preform with the API? I didn’t see an API call to give me client count for example but I had AI write the code to count the number of clients returned. The error this code returns is:
% pixlet serve UCRM_Client_Count.star
2023/10/03 19:40:42 listening at http://127.0.0.1:8080
2023/10/03 19:40:42 error loading applet: failed to load applet: starlark.ExecFile: UCRM_Client_Count.star:21:8: got illegal token, want primary expression
^C
My code:
load(“http.star”, “http”)
load(“render.star”, “render”)
UISP API Base URL
UISP_API_BASE_URL = “UISP Cloud Access Portal”
Your API Token
UISP_API_TOKEN = “XXX”
def fetch_active_clients():
headers = {
“x-auth-token”: UISP_API_TOKEN,
}
url = UISP_API_BASE_URL + “/clients”
response = http.get(url, headers=headers)
# Check for non-200 status code
if response.status_code != 200:
return None, "Error reaching UISP: " + str(response.status_code)
# Attempt to parse the response as JSON
try:
return response.json(), None
except Exception as e:
return None, "JSON decoding error: " + str(e)
def main(config):
data, error = fetch_active_clients()
if error:
return render.Root(
child = render.Text(error)
)
# Assuming the data is a list of clients, count the number of active clients
active_client_count = len([client for client in data if client.get('isActive')])
# Display the count on Tidbyt
return render.Root(
child = render.Text(str(active_client_count) + " Active Clients")
)
TIA for any help!