Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit 73f48edef084b6144689d4f8f8baa39c0fbceef6
parent d9b9841178acebcb6f34eead2276f4d4b4195d8f
Author: knutsen <samuel@knutsen.co>
Date:   Thu, 29 Apr 2021 16:42:55 +0100

Parse JSON weather response conventionally.

Diffstat:
Mlib/commands/weather.ts | 13+++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/lib/commands/weather.ts b/lib/commands/weather.ts @@ -49,7 +49,8 @@ export default async (home_scope: HomeScope) => { }; let geocoder_json, weather_info, geo_object, - country_code, tz, openweather_info, d, c; + country_code, tz, openweather_info, + weather_body, info_body, d, c; try { const geocoder = await fetch(`${GEOCODE_URL}&apikey=${geokey}` +`&geocode=${encodeURI(location)}&lang=en-US`); @@ -73,10 +74,14 @@ export default async (home_scope: HomeScope) => { `${OPENWEATHER_URL}?lat=${lat}&lon=${lon}` + `&units=metric&appid=${SECRETS.openweather.key}`); - d = await weather_info.json(); - c = await(openweather_info.json()); + weather_body = await weather_info.text(); + info_body = await openweather_info.text(); + + d = JSON.parse(weather_body) + c = JSON.parse(info_body); } catch (e) { - console.warn("met.no response: ", weather_info.text()); + console.warn("met.no response: ", weather_body); + console.warn("openweather response: "info_body); return error(e); }