Skip to content

Instantly share code, notes, and snippets.

@JDTm
Forked from ss89/fitstar.js
Last active January 14, 2023 02:17
Show Gist options
  • Save JDTm/9eb4e0e3559996483fe0697706f2a1f2 to your computer and use it in GitHub Desktop.
Save JDTm/9eb4e0e3559996483fe0697706f2a1f2 to your computer and use it in GitHub Desktop.
Fitstar capacity Status Widget
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-gray; icon-glyph: dumbbell;
//
// HEAVILY "inspired" by masselmello's "rsg_group_mcfit_high5_johnreed_capacity_widget.js"
// See: https://gist.github.com/masselmello/6d4f4c533b98b2550ee23a7a5e6c6cff
// Thanks also to SS89 for the changes from McFit to FitStar: https://gist.github.com/ss89
// Version: 1.0.1
// ## Changelog
// Version 1.0.0 24.05.2021 - First Version München Giesing only! Further versions will use Parameters!
// Version 1.0.1 26.05.2021 - Added Paramfunction, fixed read Gymname from URL, added last update time
// Version 1.0.2 12.01.2023 - Changed Perlach 2 to Perlach Plaza
let url = 'https://www.fit-star.de/fitnessstudio/muenchen-perlach-plaza'
let param = args.widgetParameter
if (param != null && param.length > 0) {
url = param
}
regex = new RegExp("([^/]+)(?=[^/]*/?$)","g")
//const gymname = regex.exec(url)
gymname = regex.exec(url)
gymname = (gymname[0])
console.log(gymname)
// List of all Studios:
/*
https://www.fit-star.de/studios/
München-Berg am Laim /fitnessstudio/muenchen-berg-am-laim
München-Giesing /fitnessstudio/muenchen-giesing
München-Laim /fitnessstudio/muenchen-laim
München-Neuhausen /fitnessstudio/muenchen-neuhausen
München-Pasing /fitnessstudio/muenchen-pasing
München-Perlach Plaza /fitnessstudio/muenchen-perlach-plaza
München-Sendling /fitnessstudio/muenchen-sendling
München-Trudering /fitnessstudio/muenchen-trudering
Berlin /fitnessstudio/berlin-moabit
Berlin-Moabit /fitnessstudio/berlin-moabit
Erlangen /fitnessstudio/erlangen-innenstadt
Erlangen-Innenstadt /fitnessstudio/erlangen-innenstadt
Frankfurt /fitnessstudio/frankfurt-innenstadt
Frankfurt-Innenstadt /fitnessstudio/frankfurt-innenstadt
Fürth /fitnessstudio/fuerth-suedstadt
Fürth-Südstadt /fitnessstudio/fuerth-suedstadt
Leipzig /fitnessstudio/leipzig-suedvorstadt
Leipzig-Südvorstadt /fitnessstudio/leipzig-suedvorstadt
Nürnberg /fitnessstudio/nuernberg-zentrum
Nürnberg-Zentrum /fitnessstudio/nuernberg-zentrum
*/
const currentGymCapacity = await fetchGymCapacity()
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)
const gymNameText = widget.addText(gymname.toString())
// const gymNameText = widget.addText("München Giesing")
gymNameText.font = Font.regularSystemFont(10)
widget.addSpacer(10)
const capacityText = widget.addText(currentGymCapacity.toString() + "%")
capacityText.font = Font.mediumRoundedSystemFont(50)
if (currentGymCapacity < 30) {
capacityText.textColor = new Color("#33cc33")
} else if (currentGymCapacity < 50){
capacityText.textColor = new Color("#ff9900")
}else{
capacityText.textColor = new Color("#ff3300")
}
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 FitStar gym
async function fetchGymCapacity() {
const req = new Request(url)
const result = await req.loadString()
r = new RegExp("JSON.parse\\(JSON.stringify\\(\\[\\[(\\d+)","g")
res = r.exec(result)
console.log(res)
return parseInt(res[1])
}
@JDTm
Copy link
Author

JDTm commented May 24, 2021

First Version for the Fit Star Widget - without parameters - hardcoded for München Giesing.
HEAVILY "inspired" by masselmello's "rsg_group_mcfit_high5_johnreed_capacity_widget.js" https://gist.github.com/masselmello/6d4f4c533b98b2550ee23a7a5e6c6cff

th_Fit_star

Download with ScriptDude

To Do List:

  • Get Studioname from Website instead of URL
  • Write Manual

@JDTm
Copy link
Author

JDTm commented May 25, 2021

How to add your Studio

Get your Studio URL here: https://www.fit-star.de/studios/
Sample: https://www.fit-star.de/fitnessstudio/berlin-moabit/
Paste it to the scriptable Parameter
th_parameter

@v4lli
Copy link

v4lli commented Jun 6, 2021

Cool! Danke :)

First Version München Giesing only

The only real one anyway ;)

@v4lli
Copy link

v4lli commented Jun 6, 2021

@JDTm I Created a quick & dirty fork of this in order to incorporate the graphs (today in yellow + same day last week in grey):

IMG_4675

You might want to have a look at the fetchGymStats function, which now parses the entire JSON object and makes the dict available as its return value. More convenient than extracting every parameter using a regex. https://gist.github.com/v4lli/b123fd0c766ad6a8f92a0df374c965bc

@JDTm
Copy link
Author

JDTm commented Jan 12, 2023

@v4lli i didn't saw your comment. Very intersting, i will fork it again, need the Studio Name + Parameter input.
The Yellow line is not working anymore?

@v4lli
Copy link

v4lli commented Jan 13, 2023

Seems to work for me

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