-
-
Save JDTm/9eb4e0e3559996483fe0697706f2a1f2 to your computer and use it in GitHub Desktop.
Fitstar capacity Status Widget
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: 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]) | |
} |
Cool! Danke :)
First Version München Giesing only
The only real one anyway ;)
@JDTm I Created a quick & dirty fork of this in order to incorporate the graphs (today in yellow + same day last week in grey):
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
@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?
Seems to work for me
Studio was "empty", so the yellow line was not visible.
When its still interesting, i found this:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to add your Studio
Get your Studio URL here: https://www.fit-star.de/studios/
![th_parameter](https://user-images.githubusercontent.com/2218600/119576968-16432d00-bdba-11eb-9106-632c1f7423d7.png)
Sample: https://www.fit-star.de/fitnessstudio/berlin-moabit/
Paste it to the scriptable Parameter