October 25, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
import process from "node:process";
// India's Pearl
let output = "**Hyderabad Weather Report**\n\n";
const accuweatherCityCode = "202190";
// fetch JSON daily from accuweather
const getForecast = async () => {
const forecastData = await fetchJSON(
`http://dataservice.accuweather.com/forecasts/v1/daily/1day/${accuweatherCityCode}?apikey=${process.env.accuWeather}&details=true&metric=true`,
);
return forecastData.DailyForecasts[0];
};
let dailyForecast = await getForecast();
const maxTemp = dailyForecast.RealFeelTemperature.Maximum.Value;
const minTemp = dailyForecast.RealFeelTemperature.Minimum.Value;
const maxTempPhrase = dailyForecast.RealFeelTemperature.Maximum.Phrase;
const minTempPhrase = dailyForecast.RealFeelTemperature.Minimum.Phrase;
const dayShortPhrase = dailyForecast.Day.ShortPhrase;
output += `Day will be ${maxTempPhrase.toLowerCase()} with a high of **${maxTemp}°C**. ${dayShortPhrase}.\n`;
// Get UV index
const uvIndex = dailyForecast.AirAndPollen.find(item => item.Name === "UVIndex").Value;
let uvRecommendation = "";
if (uvIndex >= 8) {
uvRecommendation = "SPF50+ sunscreen is advised!";
}
else if (uvIndex >= 5) {
uvRecommendation = "SPF30+ sunscreen is advised!";
}
output += `The UV index is ${uvIndex}. ${uvRecommendation}\n`;
// Get rain probability and make umbrella recommendation
const rainProbability = dailyForecast.Day.RainProbability;
let umbrellaRec = "";
if (rainProbability > 50) {
umbrellaRec = "☔️**Carry an umbrella!**";
}
output += `${rainProbability}% chance of rain today. ${umbrellaRec}\n`;
output += `Night will be ${minTempPhrase.toLowerCase()} with a low of **${minTemp}°C**.`;
// Push result to webhook
// Hyderabad Discord Server : community servers search inside discord
export const discordWebhookWeatherHyd = discordWebhook({
url: process.env.HydGenHook,
content: output,
});
console.log(output);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 25, 2023