IdkWhatever69
05/27/2023, 6:51 PMWalshy | Pages
05/27/2023, 6:52 PMIdkWhatever69
05/27/2023, 6:52 PMWalshy | Pages
05/27/2023, 6:53 PMsilence
05/27/2023, 6:54 PMIdkWhatever69
05/27/2023, 6:54 PMhttps://cdn.discordapp.com/attachments/779390076219686943/1112091451568951346/Screenshot_2023-05-28_at_12.23.54_AM.png▾
Walshy | Pages
05/27/2023, 6:54 PMWalshy | Pages
05/27/2023, 6:55 PMIdkWhatever69
05/27/2023, 6:55 PMwrangler tail
right?Walshy | Pages
05/27/2023, 6:56 PMIdkWhatever69
05/27/2023, 7:05 PMWalshy | Pages
05/27/2023, 7:06 PMWalshy | Pages
05/27/2023, 7:06 PMIdkWhatever69
05/27/2023, 7:06 PMWalshy | Pages
05/27/2023, 7:06 PMIdkWhatever69
05/27/2023, 7:06 PMIdkWhatever69
05/27/2023, 7:07 PMts
//get hourly weather
const wthr: Result<Period> = await (async () => {
const proto_res = (await (await fetch(`${WeatherAPIEndpoint}/hourly`, { body: null, method: 'GET', headers: fetch_headers})).json()) as WeatherData|undefined;
if (!exists(proto_res) || !exists(proto_res.properties.periods)) return new Err(`No data from ${WeatherAPIEndpoint}/hourly`);
const result = proto_res.properties.periods.filter(p => (dateIsoToUnixSec(p.startTime)*1000 > now))[0];
if (exists(result)) return new Ok(result);
return new Err("Data too old");
})();
if (!wthr.isOk()) return;
//get overall day dorcast
const day_forcase = await (async () => {
const proto_res = (await (await fetch(WeatherAPIEndpoint, { body: null, method: 'GET', headers: fetch_headers})).json()) as WeatherData|undefined;
if (!exists(proto_res) || !exists(proto_res.properties.periods)) return new Err(`No data from ${WeatherAPIEndpoint}`);
const result = proto_res.properties.periods.find(p => (p.number == 1));
if (exists(result)) return new Ok(result);
return new Err("Today's data not found");
})();
IdkWhatever69
05/27/2023, 7:07 PMIdkWhatever69
05/27/2023, 7:08 PMJames
05/27/2023, 7:10 PMJames
05/27/2023, 7:10 PMJames
05/27/2023, 7:11 PM.json()
James
05/27/2023, 7:11 PMproperties.periods
doesn't exist, for example.F0rce
05/27/2023, 7:12 PMtoml
[placement]
mode = "smart"
inheritable ? The docs page does not seem to have it listed.IdkWhatever69
05/27/2023, 7:16 PMIdkWhatever69
05/27/2023, 7:17 PMts
if (!exists(proto_res) || !exists(proto_res.properties.periods)) return new Err(`No data from ${WeatherAPIEndpoint}/hourly`);
i do check thatJames
05/27/2023, 7:17 PM.ok
and also check if the content-type
includes application/json
. You'd be surprised at how many APIs are wonky sometimes and return a 200 but an HTML error page or somethingJames
05/27/2023, 7:18 PM.properties
doesn't exist there, you'll get a TypeError
. I'd check proto_res.properties
exists tooIdkWhatever69
05/27/2023, 7:18 PMts
const fetch_headers = {
'User-Agent': `${fitweather_credentials.name}/1.0 (Florida Institute of Technology Weather Discord Bot (Student Run), https://github.com/DaBigBlob/FIT-Weather-Chan)`,
'Accept': "application/geo+json"
};