Last active
May 24, 2021 12:47
-
-
Save ss89/646aae34f87ab620327f97bfb38c5d89 to your computer and use it in GitHub Desktop.
fitstar
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
/** | |
* Script for scriptable to get the current capacity of Fitstar Gyms | |
* HEAVILY "inspired" by masselmello's "rsg_group_mcfit_high5_johnreed_capacity_widget.js" | |
* See: https://gist.github.com/masselmello/6d4f4c533b98b2550ee23a7a5e6c6cff | |
*/ | |
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) | |
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("München Giesing") | |
gymNameText.font = Font.regularSystemFont(12) | |
} | |
//Fetches the current capacity of the McFit gym | |
async function fetchGymCapacity() { | |
const url = 'https://www.fit-star.de/fitnessstudio/muenchen-giesing/' | |
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