Skip to content

Script to retrieve Weather report from National Weather Service #299

Answered by chhoumann
TheHuntyBadger asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @TheHuntyBadger

Here's a quick script that fetches the weather from the endpoint you've mentioned.

module.exports = async (QuickAdd) => {
    const fetchRes = await requestUrl("https://api.weather.gov/gridpoints/PSR/105,73/forecast");
    
    if (fetchRes.status !== 200) {
        new Notice("Error fetching weather data.");
    }

    const { properties } = fetchRes.json;
    const [now] = properties.periods;

    QuickAdd.variables = {
        ...now,
    };
};

Now, any value associated with the now period will be put in variables you can use in captures/templates, e.g. ``{{VALUE:temperature}}`.

Here's what is associated with the most recent period, as of writing:

{
	"number": 1,
	"n…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by TheHuntyBadger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants