Skip to content

Instantly share code, notes, and snippets.

@eopo
Last active January 28, 2024 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eopo/f0dc692f23e2373000df6134b7b4e4e0 to your computer and use it in GitHub Desktop.
Save eopo/f0dc692f23e2373000df6134b7b4e4e0 to your computer and use it in GitHub Desktop.
iOS widget powered by the Scriptable app that shows the current capacity of your XtraFIT gym
/**
* Script for scriptable to get the current capacity of XTRAFIT Gyms
*/
let gymId = 210
let param = args.widgetParameter
if (param != null && param.length > 0) {
gymId = param
}
const gymDetails = await fetchGymDetails(gymId)
const currentGymCapacity = await fetchGymCapacity(gymDetails)
const gymName = gymDetails.webName
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 XTRAFit gym
async function fetchGymDetails(id) {
const url = 'https://xtrafitclubsdynamic.hirschenvalley.de/application'
const req = new Request(url)
req.headers = {"Content-Type": "application/json"}
const apiResult = await req.loadJSON()
for (var i in apiResult){
if(apiResult[i].centerId == id)
{
return apiResult[i]
}
}
return {webName: 'Studio nicht gefunden', currentlyCheckedInCount: 0, maximumAllowedCheckedIn: 0}
}
//Fetches the Capacity of the gym
async function fetchGymCapacity(gymDetails) {
return gymDetails.currentlyCheckedInCount * 100 / gymDetails.maximumAllowedCheckedIn || 0
}
@dennismetz
Copy link

Super, danke!

Ich habe das Script mal angepasst, hier ist die aktuelle Version:

https://gist.github.com/dennismetz/611b1e8f64c2160c8f24253f792fa0b6

IMG_0698

@Jonas-wav
Copy link

@N1c093 Das hatte ich auch gesehen, bin aber am Script gescheitert. Danke @dennismetz <3

@eopo
Copy link
Author

eopo commented Jan 28, 2024

Ich habe die Beschreibung mal angepasst und auf @dennismetz' Repo verwiesen. Der Übersichtlichkeit halber würde ich vorschlagen, den Austausch dann auch dort weiterzuführen.

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