Last active
March 26, 2024 14:16
McFit Trier scriptable script to check current capacity
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 McFit Gyms | |
*/ | |
let gymId = 1613591080 | |
let param = args.widgetParameter | |
if (param != null && param.length > 0) { | |
gymId = param | |
} | |
const currentGymCapacity = await fetchGymCapacity(gymId) | |
const storeInfo = await fetchGymInfo(gymId) | |
const gymName = await fetchGymInfo(gymId) | |
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(30) | |
const capacityText = widget.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") | |
} | |
widget.addSpacer(1) | |
const gymNameText = widget.addText(gymName) | |
gymNameText.font = Font.regularSystemFont(12) | |
} | |
//Fetches the current capacity of the McFit gym | |
async function fetchGymCapacity(id) { | |
const url = `https://my.mcfit.com/nox/public/v1/studios/${id}/utilization/v2/today` | |
const req = new Request(url) | |
req.headers = { | |
'x-tenant': 'rsg-group' | |
} | |
const result = await req.loadJSON() | |
return result.find((item) => item.current)?.percentage ?? 0 | |
} | |
//Fetches the name of the gym | |
async function fetchGymInfo(id) { | |
const url = 'https://rsg-group.api.magicline.com/connect/v1/studio?studioTags=MCFIT-2DBEBDE87C264635B943F583D13156C0' | |
const req = new Request(url) | |
const apiResult = await req.loadJSON() | |
for(var i in apiResult){ | |
if(apiResult[i].id == id){ | |
return apiResult[i].studioName | |
} | |
} | |
return 'Your McFit' | |
} |
Author
clemone210
commented
May 25, 2023
•
Is it possible that rsg changed the url? I am using it foor Home Assistant and it doesn't work anymore. When i put the url in my browser it says 404 not found.
Indeed, it does not work for me either anymore.
Maybe scriptable changed as well.
I did not look into it yet, maybe I will do this weekend.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment