Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save masselmello/6d4f4c533b98b2550ee23a7a5e6c6cff to your computer and use it in GitHub Desktop.
Save masselmello/6d4f4c533b98b2550ee23a7a5e6c6cff to your computer and use it in GitHub Desktop.
iOS widget powered by the Scriptable app that shows the current capacity of your McFit gym (RSG group)
/**
* Script for scriptable to get the current capacity of McFit Gyms
*/
let gymId = 1731068920
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://www.mcfit.com/de/auslastung/antwort/request.json?tx_brastudioprofilesmcfitcom_brastudioprofiles%5BstudioId%5D=' + 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 apiResult[i].studioName
}
}
return 'Your McFit'
}
@martinbackes
Copy link

ja klar würde das Sinn machen mit der aktuellen "kein Netzwerk" Anzeige, aber es sieht einfach nicht gut aus so wie es über die Widgets standardmäßig dargestellt wird und ist gegenüber allem Anderen nicht gestaltet, deswegen würde ich meine Variante bzw Vorschlag vorziehen, weil es ja dann eine Indikation bzw eine Visualisierung gibt, dass kein Netzwerk vorherrscht :)

@masselmello
Copy link
Author

Genau das meinte ich ja. Nur ein hübscher Netzwerkfehler, aber ohne die misleading Anzeige des letzten Werts.

@martinbackes
Copy link

Hey, wir müssen da jetzt auch keine riesen Diskussion daraus machen :) aber das Netz ist ja in den meisten Fällen da, und wenn nicht, bin ich wahrscheinlich im Bett, Flieger, Meeting oder ähnliches und entscheide mich mit Sicherheit nicht, ob ich jetzt ins Gmy gehe oder nicht. Was aber da ist, ist diese Anzeige, die den halben Screen so aussehen lässt, als hätte jemand die Gestaltung vergessen und das hat für mich nichts mit Aufhübschung zu tun. Deswegen ist das für mich nicht misleading, sondern ein eingefrorener Zustand der visualisiert wird. Und ich weiß ja, dass der Wert eingefroren ist :)

@masselmello
Copy link
Author

masselmello commented Oct 28, 2020

Genau die Diskussion is unnötig. Kannst es dir ja so anpassen, dass es deinen Wünschen entspricht. :) Dafür hab ichs ja Open Source gemacht 😉

@martinbackes
Copy link

ja, weiß ich doch, und war ja nicht doof gemeint :) Danke noch einmal dafür 🙏😀

@SmartHomeGuy
Copy link

@SmartHomeGuy Für CleverFit nicht, weil die API scheiße ist. Das ist mir zu viel Aufwand. Sorry :/

Alles klar, danke für die Info 👍

@iToab
Copy link

iToab commented Nov 1, 2020

@masselmello
Hey,
Hat das jemand vielleicht schon für Jumpers Fitness angepasst?
https://www.jumpers-fitness.com/studios/
Wäre super 👍🏻

@masselmello
Copy link
Author

@ssibio17 Habs mir Mal kurz angeschaut, scheint mir auf den ersten Blick aber einfach eine HTML-Seite zu sein, die alle 30 Sekunden mit neuen Werten neu geladen wird. Der Source-Code ist aber auch katastrophal.

@iToab Scheint möglich, aber der Source-Code ist ebenfalls ziemlich unübersichtlich, also leider doch etwas sehr aufwendig.
Mal schauen vlt. wird was möglich, will aber nichts versprechen, hab nur ganz kurz nebenbei reingeschaut.

@matzepipo
Copy link

matzepipo commented Nov 15, 2020

Hätte das gern für Xtrafit Studios. Wäre das auch möglich ?

Ah gesehen, gibt es schon

Wie komme ich an die gym Id von Xtrafit köln buchheim ??

Gym ID Xtrafit (ein paar gefunden)
200 Köln Ehrenfeld
210 Essen-Volgelheim
220 Köln Buchheim
230 Krefeld-Cracau
240 Mainz-Bretzenheim
270 Köln Marsdorf
300 Offenbach Zentrum

@JDTm
Copy link

JDTm commented May 21, 2021

Hat jemand noch Zeit sich FitStar anzuschauen? Update: Ich arbeite grad an einem FitStar Widget.

@madnoize
Copy link

madnoize commented Feb 4, 2023

Hey is schon ne weile her aber bei mir funktionieren die high5 Studios nicht hat sich da was geändert ?

@clemone210
Copy link

Für die Leute, bei denen es nicht funktioniert.
Ich habe eine funktionierende Version, inkl. der Studios und deren Tags + URL zum anpassen.
https://gist.github.com/clemone210/8f1b150a2c4f1fac0c409e6d21d656e2

@lorenzlars
Copy link

lorenzlars commented Nov 25, 2023

If someone has issues with the widget because of the recent API change on McFit side. Just replace the fetchGymCapacity with this implementation:

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
}

@bondskin
Copy link

bondskin commented Dec 5, 2023

thanks @lorenzlars , it works now again

@marvinjoa
Copy link

Sehr nice, dass ich nichtmal die gymID ändern musste, weil der OP wohl mal im gleichen Gym trainiert hat :D

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