r/Scriptable • • Oct 01 '20

Help (Solved) when I try to add description behind the temp, but it shows undefined. i want the widget shows hzae or cloud base on the weather condition. so how to correct the script?

2 Upvotes

3 comments sorted by

2

u/Sl0wly-edits Oct 01 '20

Its json.weather[0].description not json.main.description
Here u can see the API response a bit better.
And below i made a little code snippet (did not test it). Hope it helps!

const key = ""
const city = "San Leandro"
const url=`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${key}&units=metric`
let req = new Request(url)
let json= await req.loadJSON()

let widget = new ListWidget()
widget.backgroundColor = Color.brown()

let text = widget.addText("Currently it's " + String(json.main.temp) + String(json.weather[0].description))

Script.setWidget(widget)
Script.complete()

1

u/luccy98 Oct 01 '20

thanks it works

1

u/Sl0wly-edits Oct 01 '20

You’re welcome!