Forked from masselmello/rsg_group_mcfit_high5_johnreed_capacity_widget.js
Last active
May 13, 2023 09:11
-
-
Save ghoeffner/046b7212b09b4d20ede00ff980e03b6c to your computer and use it in GitHub Desktop.
iOS widget powered by the Scriptable app that shows the current capacity of your Elements Fitness & Wellness Gym
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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: green; icon-glyph: dumbbell; | |
/** | |
* Script for scriptable to get the current capacity of Elements Fitness Gyms | |
* Originally written for McFit by masselmello, changed for elements by ghoeffner | |
*/ | |
let gymId = "ELEMENTS-DONN" | |
let gymName = 'Elements Donnersbergerbrücke' | |
let param = args.widgetParameter | |
if (param != null && param.length > 0) { | |
gymId = param | |
} | |
const currentGymCapacity = await fetchGymCapacity(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("🏋️ Auslastung") | |
headlineText.font = Font.mediumRoundedSystemFont(19) | |
widget.addSpacer(25) | |
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) | |
widget.addSpacer(10) | |
let df = new DateFormatter() | |
df.dateFormat = 'HH:mm' | |
const lastupdate = widget.addText( | |
`Stand: ${df.string(new Date())}` | |
); | |
lastupdate.font = Font.regularSystemFont(10) | |
} | |
//Fetches the current capacity of the McFit gym | |
async function fetchGymCapacity(id) { | |
const url = 'https://connect.e-app.eu:57319/easyWeb.svc/eApps/widgets' | |
const req = new Request(url) | |
req.method="POST" | |
req.body='{"call":"GeteLiveauslastung","param":{},"useWS":0,"studio":"' + gymId + '"}' | |
const result = await req.loadJSON() | |
var counter = 0 | |
counter = result.Wert1 | |
return counter | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment