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])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment