Skip to content

Instantly share code, notes, and snippets.

@achhunna
Last active May 7, 2021 15:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achhunna/9ef8b4306549bc2f438e929ff52919dd to your computer and use it in GitHub Desktop.
Save achhunna/9ef8b4306549bc2f438e929ff52919dd to your computer and use it in GitHub Desktop.
`How's the surf` script scraping Surfline
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: cyan; icon-glyph: swimmer;
// Checks surf height at Pacifica Lindmar beach
const url = "https://www.surfline.com/surf-report/pacifica-lindamar/5842041f4e65fad6a7708976"
const webview = new WebView()
await webview.loadURL(url)
var getData = `
const baseClass = ".sl-spot-forecast-summary "
const match = {
"-": " to ",
"ft": " feet",
}
function getData() {
const height = document.querySelector(baseClass + ".sl-spot-forecast-summary__stat-container--surf-height .quiver-surf-height").innerText
const temperature = document.querySelector(baseClass + ".sl-wetsuit-recommender .sl-wetsuit-recommender__conditions__weather div").childNodes[1].nodeValue
return "surf height is " + height.replace(/-|ft/gi, m => match[m]) + " and weather is " + temperature + " degrees."
}
getData()
`
let response = await webview.evaluateJavaScript(getData, false)
console.log(response)
if (config.runsWithSiri) {
if (response.length > 0) {
Speech.speak(" Currently, in Pacifica, " + response)
} else {
Speech.speak("Oops, Something went wrong")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment