Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eopo/b0df56edbfc0df816adbf4a54047adbf to your computer and use it in GitHub Desktop.
Save eopo/b0df56edbfc0df816adbf4a54047adbf to your computer and use it in GitHub Desktop.
iOS widget powered by the Scriptable app that shows the current capacity of McFit, John Reed, High5 and JOHN & JAME'S Gyms (RSG group)
/**
* Script for scriptable to get the current capacity of McFit, John Reed, High5 and JOHN & JAME'S Gyms
*/
let gymId = 1210252920
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()
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 John Reed gym
async function fetchGymCapacity(id) {
const url = 'https://typo3.johnreed.fitness/studiocapacity.json?studioId=' + id
const req = new Request(url)
const result = await req.loadJSON()
var counter = 0
for (var i in result.items) {
if(result.items[i].isCurrent){
counter = result.items[i].percentage
}
}
return counter
}
//Fetches the name of the gym
async function fetchGymInfo(id) {
const url = 'https://rsg-group.api.magicline.com/connect/v1/studio?studioTags=AKTIV-391B8025C1714FB9B15BB02F2F8AC0B2'
const req = new Request(url)
const apiResult = await req.loadJSON()
for (var i in apiResult){
if(apiResult[i].id == id)
{
return studioName = apiResult[i].studioName;
}
}
return 'Your Gym'
}
@eopo
Copy link
Author

eopo commented Oct 24, 2020

Moin!
Gibt es auch für das Fitnessstudio Elan eine solche Auslastungsgrenze? Kannst Du da mal nachschauen? https://elan-fitness.de/

Vielen Dank!

Nein. Ich kann nur die Daten verarbeiten, die das Fitnessstudio selbst schon irgendwo bereitstellt. Da Elan auf seiner Website keine solche Daten hat, kann ich sie auch nicht auswerten.

@Svevak
Copy link

Svevak commented Aug 4, 2021

Hallo,
erstmal super Widget, vielen Dank! Aber leider scheint es, zumindest bei mir, seit geraumer Zeit nicht mehr zu funktionieren. Vermute es hängt am "capacity json" (https://typo3.johnreed.fitness/studiocapacity.json), welches keine Werte mehr zurückgibt, oder? Gibt es hier möglicherweise eine neue Abruf-URL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment