Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
}
@eopo

This comment has been minimized.

Copy link
Owner Author

@eopo eopo commented Oct 26, 2020

Fork of https://gist.github.com/masselmello/6d4f4c533b98b2550ee23a7a5e6c6cff

image

How to use:

  1. You need to have Scriptable on your iOS 14 device and open it
  2. Tap on the plus in the upper right corner
  3. Tap on "Untitled Script" and give the script a name, for example "Gym Capacity"
  4. Copy the source code from above and paste it in the blank field
  5. Save it.
  6. Go to your home screen and enter wiggle mode. Then tap on the plus in the upper left corner.
  7. Select Scriptable from the promoted widgets, the app list or search for scriptable.
  8. Select your widget size.
  9. Tap on "Add widget"
  10. Tap on the newly added widget.
  11. Select the John Reed script. On "When Interacting", you can select "Run Script", but it'll work just fine with "Open App"
  12. Paste your studio ID as parameter. You can see it in the table below.
    image
  13. Finished! 😍
Studio ID
Bonn-Zentrum 310
Essen-Vogelheim 210
Frankfurt Nieder-Eschbach 280
Hamburg-Wandsbek 320
Krefeld-Cracau 230
Köln-Buchheim 220
Köln-Ehrenfeld 200
Köln-Marsdorf 270
Köln-Ossendorf 250
Langenfeld-Berghausen 290
Mainz-Bretzenheim 240
Offenbach-Zentrum 300
Wiesbaden-Hauptbahnhof 260
Zentrale 100
@matzepipo

This comment has been minimized.

Copy link

@matzepipo matzepipo commented Apr 3, 2021

Ist da eine Störung??????
Bekomme keine Verbindung mehr

@matzepipo

This comment has been minimized.

Copy link

@matzepipo matzepipo commented Jun 6, 2021

Nochmal ich. Das Script funktioniert irgendwie nicht mehr mit dem Xtrafit Studio.

Kann sich das mal jemand ansehen ?

Gruß

Stefan

Script didn’t work with Xtrafit. Could anybody fix it ?

Stefan

@max-sti

This comment has been minimized.

Copy link

@max-sti max-sti commented Jul 29, 2021

2021-07-29 09:56:58: Error: Das Zertifikat für diesen Server ist ungültig. Eventuell wird eine Verbindung mit einem Server hergestellt, der vorgibt, „xtrafitclubsdynamic.hirschenvalley.de“ zu sein und vertrauliche Daten gefährdet.

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