Skip to content

Instantly share code, notes, and snippets.

@JiceDessaint
Created September 22, 2020 12:17
Show Gist options
  • Save JiceDessaint/f375ba17ad00734125fa4d725940b2dc to your computer and use it in GitHub Desktop.
Save JiceDessaint/f375ba17ad00734125fa4d725940b2dc to your computer and use it in GitHub Desktop.
Scriptable Nestor Menu Widget
let widget = new ListWidget()
// Background
let startColor = new Color("ff7b1c")
let endColor = new Color("fe9e0b")
let gradient = new LinearGradient()
gradient.colors = [startColor, endColor]
gradient.locations = [0.0, 1]
widget.backgroundGradient = gradient
// Title
let title = widget.addText("Nestor Today 👩‍🍳")
title.textColor = new Color("FFFFFF", 1)
title.centerAlignText()
title.font = new Font("", 20)
widget.addSpacer(30)
await parseHtml()
widget.presentLarge()
Script.setWidget(widget)
async function parseHtml() {
let url = "http://www.nestorparis.com"
let req = new Request(url)
let html = await req.loadString()
let boxesHtml = html.split("le menu du jour")
boxesHtml.shift()
let index = (new Date()).getDay() - 1
await parseMenu(boxesHtml[index])
}
async function parseMenu(html) {
imageUrl = html.match(/src="(\/static[^"]*)/)[1]
let items = html.split("_co _e8 _hb _cr\">").slice(1).map(x => x.split("<")[0])
let req = new Request(`http://www.nestorparis.com${imageUrl}`)
let image = await req.loadImage()
let widgetImage = widget.addImage(image)
widgetImage.centerAlignImage()
widgetImage.cornerRadius = 10
widget.addSpacer(30)
let starter = widget.addText(`🍲 ${items[0]}`)
starter.textColor = new Color("FFFFFF", 1)
widget.addSpacer(5)
let main = widget.addText(`🥘 ${items[1]}`)
main.textColor = new Color("FFFFFF", 1)
widget.addSpacer(5)
let dessert = widget.addText(`🧁 ${items[2]}`)
dessert.textColor = new Color("FFFFFF", 1)
widget.addSpacer(12)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment