URLfetch: Unexpected identifier 'Server'

I’m trying to get some weather data using openweathermap, and I’m having a few issues. I narrowed it down to expressions not working inside urlfetch or something, is there any other way to do this?

$(eval const l= $(urlfetch json https://rtirl.com/api/pull?key=<API key>);const w=$(urlfetch json https://api.openweathermap.org/data/2.5/weather?lat=${l.location.latitude}&lon=${l.location.longitude}&appid=<API key>);w.main.temp)

first of all, i really hope it’s not typed exactly like that in the command and that u were just careful to remove your api key before posting here… otherwise the lack of api key is likely your issue…

secondly, idk if that api would give specific data that u’re looking for or something, but nightbot has a built in $(weather) feature… if it’s to avoid disclosing your city, u can prevent that like this…

$(eval let a=`$(weather YOUR_LOCATION)`;a=a.replace(`YOUR_LOCATION`,`$(channel)`);a)

and just replace YOUR_LOCATION with the location of the weather u’re looking for (NOTE: it is case sensitive, so u’ll have to spell it how they do, proper caps and such)

Thanks! That solution could work if $(weather) accepted coordinates, but I have not managed to make that work.

oh, ok, um… well nightbot doesn’t accept anything into command variable except as input from another source… so u’d need to split that up and do the first $(urlfetch) in a command by itself and then alias that command to a second command for the rest of it… like this…

$(eval const l=$(urlfetch json https://rtirl.com/api/pull?key=<API key>);`${l.location.latitude} ${l.location.longitude}`)

and for the second command…

$(eval const w=$(urlfetch json https://api.openweathermap.org/data/2.5/weather?lat=$(1)&lon=$(2)&appid=<API key>);w.main.temp)

edit: ok, i misspoke slightly, it will only accept data as input from an outside source OR hard coded directly in the command variable… so if u knew those coordinates offhand, u could plug them directly into that second command and skip the first one altogether… in fact i’d probly recommend that so it would only have to do a single urlfetch and respond faster :wink: (note: u could run the first command without it being aliased to get that info and then just replace the $(1) and $(2) )

1 Like

Thank you! And yes, of course I redacted the API keys :slight_smile:

1 Like