Weather Plugin For Kirby?


#1

Has anyone here created a weather plugin or used any existing weather APIs and plugged it into their kirby site?
I’ve got no idea where to start with something like that and any help would be much appreciated.


#2

What is your use case?

It is actually not very difficult to make an API call in Kirby using the Toolkit’s remote class.

The more difficult task is probably to choose the right API for the purpose, depending on the locations you need to cover, whether or not the API needs to have a free account or not etc.

Here is some example PHP code for the Apixu-Api: https://github.com/apixu/apixu-php; the same logic can actually be applied to any other API and in Kirby you can use remote::request() to make the cURL call even easier.


#3

I used this: https://www.weatherbit.io/api/weather-forecast-16-day in a GoogleSheet.


#4

I’m currently building a charity website which uses the DarkSky api to pull in the current weather at locations around the UK.

The API details are here:

https://darksky.net/dev/docs#api-request-types

The charity has centres around the UK and each centre has its own page on the website. On the page I have fields for latitude and longitude which are passed to the DarkSky api using Kirby’s remote::request tool.

You can see an example of it in action on the test site here:

(the weather forecast is below the map)


#5

I need it to show the current weather in San Diego and then have the icon change based on whether it’s rainy, cloudy, sunny, snowing, etc.


#6

I would consider caching the result from the API somehow… you probably don’t want every single site visit hitting the API so I would maybe use a cron job or something to hit the API every six hours, save the data, and get the site to pick up from the stored result. If it was stocks and shares or something like that, you would want a real time result, but lets face it, the weather doesn’t change that fast :slight_smile:

This way you can probably get around any free account limitations APIs might have., too.


#7

Most GNU/Linux implement widgets of some kind relying on OpenWeatherMap. Their API is well documented, you just need a (free) API key.

Also, there’s a PHP implementation that should do the trick. They also support caching.