Skip to content

Instantly share code, notes, and snippets.

@supermamon
Created June 29, 2021 12:33
Show Gist options
  • Save supermamon/0b74b64e63b04bcb60231934bf4dbbe0 to your computer and use it in GitHub Desktop.
Save supermamon/0b74b64e63b04bcb60231934bf4dbbe0 to your computer and use it in GitHub Desktop.
bare minimum dual temperature widget for scriptable
// bare minimum dual temperature widget for scriptable
// by @supermamon
// 29 June 2021
// get from https://openweathermap.org/appid
const api_key = 'your-api-key'
// get location
const loc = await Location.current()
// https://openweathermap.org/current
const url = `https://api.openweathermap.org/data/2.5/weather?lat=${loc.latitude}&lon=${loc.longitude}&appid=${api_key}`
const req = new Request(url)
const data = await req.loadJSON()
const tempK = data.main.temp
const tempC = Math.trunc(Math.round(tempK-273.15))
const tempF = Math.trunc(Math.round(tempC*9/5+32))
// create the widget
const w = new ListWidget()
w.addSpacer()
w.addText(`${tempC} °C`).centerAlignText()
w.addText('--------').centerAlignText()
w.addText(`${tempF} °F`).centerAlignText()
w.addSpacer()
Script.setWidget(w)
if (config.runsInApp) await w.presentSmall()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment