Created
February 11, 2025 16:02
-
-
Save drmohundro/44a4e3c865a7250b0b128a55a6fc1415 to your computer and use it in GitHub Desktop.
Obsidian Templater Snippet to display weather
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const forecast = await fetch("https://wttr.in/Memphis?format=j1").then((res) => | |
res.json(), | |
); | |
const temp = forecast.current_condition[0].temp_F; | |
const feelsLike = forecast.current_condition[0].FeelsLikeF; | |
const description = forecast.current_condition[0].weatherDesc[0].value; | |
const weatherCode = forecast.current_condition[0].weatherCode; | |
// via https://github.com/chubin/wttr.in/blob/4d384f9efe727b28a595d4f502bcb9593fa19c99/lib/constants.py | |
const WWO_CODE = { | |
113: "Sunny", | |
116: "PartlyCloudy", | |
119: "Cloudy", | |
122: "VeryCloudy", | |
143: "Fog", | |
176: "LightShowers", | |
179: "LightSleetShowers", | |
182: "LightSleet", | |
185: "LightSleet", | |
200: "ThunderyShowers", | |
227: "LightSnow", | |
230: "HeavySnow", | |
248: "Fog", | |
260: "Fog", | |
263: "LightShowers", | |
266: "LightRain", | |
281: "LightSleet", | |
284: "LightSleet", | |
293: "LightRain", | |
296: "LightRain", | |
299: "HeavyShowers", | |
302: "HeavyRain", | |
305: "HeavyShowers", | |
308: "HeavyRain", | |
311: "LightSleet", | |
314: "LightSleet", | |
317: "LightSleet", | |
320: "LightSnow", | |
323: "LightSnowShowers", | |
326: "LightSnowShowers", | |
329: "HeavySnow", | |
332: "HeavySnow", | |
335: "HeavySnowShowers", | |
338: "HeavySnow", | |
350: "LightSleet", | |
353: "LightShowers", | |
356: "HeavyShowers", | |
359: "HeavyRain", | |
362: "LightSleetShowers", | |
365: "LightSleetShowers", | |
368: "LightSnowShowers", | |
371: "HeavySnowShowers", | |
374: "LightSleetShowers", | |
377: "LightSleet", | |
386: "ThunderyShowers", | |
389: "ThunderyHeavyRain", | |
392: "ThunderySnowShowers", | |
395: "HeavySnowShowers", | |
}; | |
const WEATHER_SYMBOL = { | |
Unknown: "β¨", | |
Cloudy: "βοΈ", | |
Fog: "π«", | |
HeavyRain: "π§", | |
HeavyShowers: "π§", | |
HeavySnow: "βοΈ", | |
HeavySnowShowers: "βοΈ", | |
LightRain: "π¦", | |
LightShowers: "π¦", | |
LightSleet: "π§", | |
LightSleetShowers: "π§", | |
LightSnow: "π¨", | |
LightSnowShowers: "π¨", | |
PartlyCloudy: "β οΈ", | |
Sunny: "βοΈ", | |
ThunderyHeavyRain: "π©", | |
ThunderyShowers: "β", | |
ThunderySnowShowers: "β", | |
VeryCloudy: "βοΈ", | |
}; | |
const weatherLookupName = WWO_CODE[weatherCode] || "Unknown"; | |
const weatherIcon = WEATHER_SYMBOL[weatherLookupName] || WEATHER_SYMBOL.Unknown; | |
const output = `${description} ${temp}(${feelsLike}) Β°F ${weatherIcon}`; | |
tR += `# ${weatherIcon} Weather\n\n` | |
tR += output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: just wrap it in a
<%*
and%>
, will then look like this: