Created
June 29, 2021 12:33
-
-
Save supermamon/0b74b64e63b04bcb60231934bf4dbbe0 to your computer and use it in GitHub Desktop.
bare minimum dual temperature widget for scriptable
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 characters
// 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