Last active
April 7, 2024 12:23
-
-
Save DanielStefanK/adf0fc40d08585e4167f20463fe3b1d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Script for scriptable to get the current capacity of FitX Gyms | |
*/ | |
let gymId = 1265369 | |
let api = "https://fitx-proxy.daniel-stefan.dev/api/utilization/" | |
let param = args.widgetParameter | |
if (param != null && param.length > 0) { | |
gymId = param | |
} | |
const gymDetails = await fetchGymDetails(gymId) | |
const currentGymCapacity = gymDetails.workload | |
const gymName = gymDetails.name || 'Your FitX' | |
const widget = new ListWidget() | |
await createWidget() | |
if (!config.runsInWidget) { | |
await widget.presentSmall() | |
} | |
Script.setWidget(widget) | |
Script.complete() | |
//Create the widget | |
async function createWidget() { | |
const headlineText = widget.addText("🏋️ Capacity") | |
headlineText.font = Font.mediumRoundedSystemFont(19) | |
widget.addSpacer() | |
const widgetStack = widget.addStack() | |
widgetStack.layoutVertically() | |
widgetStack.bottomAlignContent() | |
const capacityText = widgetStack.addText(currentGymCapacity.toString() + "%") | |
capacityText.font = Font.mediumRoundedSystemFont(50) | |
if (currentGymCapacity < 20) { | |
capacityText.textColor = new Color("#33cc33") | |
} else if (currentGymCapacity < 30){ | |
capacityText.textColor = new Color("#ff9900") | |
}else{ | |
capacityText.textColor = new Color("#ff3300") | |
} | |
widgetStack.addSpacer(1) | |
const gymNameText = widgetStack.addText(gymName) | |
gymNameText.font = Font.regularSystemFont(12) | |
} | |
//Fetches the current capacity of the FitX gym | |
async function fetchGymDetails(id) { | |
const url = api + gymId | |
const req = new Request(url) | |
const result_json = await req.loadString() | |
return JSON.parse(result_json) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simplified version of this.
Studio Id can be obtained here https://fitx-proxy.daniel-stefan.dev