Daily weather from wttr.in in daily note

Things I have tried

  • searching the forum, internet and discord

What I’m trying to do

I try to get the repsonse from https://wttr.in/Berlin?0 into my daily note via templater user script. my script looks the follwing:

async function wheathernow() {

	return curl "https://wttr.in/Berlin?0";

}

module.exports = wheathernow;

in saves as wheathernow.js and recognized by the templater options. in my template I use the following:

<% tp.user.wheathernow() %>

But all I get is

Templater Error: Template parsing error, aborting.

for all templates that I use :-/ is there a typo I don’t see or a general mistake in my approach?

Thanks in advance and have a sunny day!

This works in local tests (care with the spelling of weather not wheather):

1. Templater > User function name

getWeather

2. Templater > User function command

curl wttr.in/Berlin\?format="%l:+%c+%t+feels+like+%f\nSunrise:+%S\nSunset:++%s\nMoon:++++%m\n"

3. In the template itself

<% tp.user.getWeather() %>

4. Results in


Weather: Berlin: :sunny: -5°C feels like -6°C
Sunrise: 06:53:58
Sunset: 17:44:25
Moon: :waxing_gibbous_moon:


Not exactly what you want but hopefully helps with troubleshooting.

1 Like

So it should rather be done with User System Commmand Functions instead of a User Script Function JS file?

1 Like

As long as your trying to replicate something done in the command line, you’ll need to use the system command interface. Or you’d need to look into how to do system calls from within javascript.

If it’s done from within the javascript environment, then you’d use a user script function.

1 Like

I really don’t know the answer to that. Was just trying to show one way of working. Think @holroy has given the info you need (way beyond what I understand).

Good luck. Hope it warms up in Berlin (if that’s where you are). :cold_face:

1 Like

You can also do it like this without needing to use curl or user scripts:

<%*
const weather = await requestUrl('https://wttr.in/Berlin?format=%25l:+%25c+%25t+feels+like+%25f%5CnSunrise:+%25S%5CnSunset:++%25s%5CnMoon:++++%25m')
tR += weather.text
%>

If you want it in a user script for whatever reason, just use requestUrl instead of curl:

async function wheathernow() {
  const weather = await requestUrl('https://wttr.in/Berlin?format=%25l:+%25c+%25t+feels+like+%25f%5CnSunrise:+%25S%5CnSunset:++%25s%5CnMoon:++++%25m')
  return weather.text
}
module.exports = wheathernow;
1 Like

If I drop that into a template and then run the template, it doesn’t work: aborting tR.

Can you please explain what I should do?

No idea sorry - here’s it working perfectly in the Sandbox vault.

  • You are using Templater plugin right?
  • And you definitely have <%*?
  • And you pasted as plain-text using Ctrl+Shift+V?

Obsidian_ksMMLZPE4T

1 Like

Doh! I had forgotten to paste with plain text. Sorry for wasting your time. :scream_cat::face_with_open_eyes_and_hand_over_mouth::cry:

THANK YOU.

Hi @spree1 , I just would like to point out some issues.

First of all if you’re using an ordinary template invocation, you’ll get the weather at the time of invocation, and it’ll not update after the first run. If that’s what you want, go for it.

If you want it to update I see two viable options, either use the dynamic template invocation, which would look something like:

<%+ tp.user.weatherNow(tp) %>

This, with the correct corresponding user function would update each time you switch to reading view.

It could possibly be wise to allow the user function to take another parameter, like the town/place you want the weather from.

The alternate method to keep updating the weather both in live preview and reading would be to use dataviewjs in accordance with the call provided by @AlanG , you could do something like:

```dataviewjs 
const weather = await requestUrl('https://wttr.in/Berlin?format=%25l:+%25c+%25t+feels+like+%25f%5CnSunrise:+%25S%5CnSunset:++%25s%5CnMoon:++++%25m')
dv.paragraph(weather.text)
```

So it kind of comes down to whether you want the weather report just once, or repeated updates, and whether you want it in live preview and/or reading view.

1 Like

Thanks for the input! Works fantastic. I just played around a little bit with URL to get the output format I wanted!

@holroy you’re absolutely right and also want the insert the weather at the point of template invocation, in order to have some kind of history within my daily notes :slight_smile:

I like that use case. Nice concept.

I was thinking more along the lines of having notes for various places which peak my interest somehow, and then have such a snippet to describe the weather there just now.

Glad you found your answer, though!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.