Created
June 29, 2021 12:33
-
-
Save supermamon/0b74b64e63b04bcb60231934bf4dbbe0 to your computer and use it in GitHub Desktop.
Revisions
-
supermamon created this gist
Jun 29, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ // 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()