March 2023 Archives

Weather::WeatherKit and Weather::Astro7Timer

Today, the popular Dark Sky weather API is shutting down. I did a little write-up for non-Perl devs on, but I thought I'd post here a couple of potentially useful modules I released to CPAN recently. 

Weather::WeatherKit accesses the WeatherKit REST API, which is Apple's official Dark Sky replacement. The module uses Crypt::JWT to create tokens, so accessing WeatherKit then is as simple as:

use Weather::WeatherKit;

my $wk = Weather::WeatherKit->new(
    team_id    => $apple_team_id,
    service_id => $weatherkit_service_id,
    key_id     => $key_id,
    key        => $private_key

my %report = $wk->get(
    lat      => 51.2,
    lon      => -1.8,
    dataSets => 'currentWeather'

Of course, this API is sort of free, as it requires an Apple developer account. If you don't have one and don't want to get one, there are some alternative APIs, but for the purposes of this post I'll stick to 7Timer, via Weather::Astro7Timer. Even simpler, as it does not need authentication:

use Weather::Astro7Timer;

my $w7t = Weather::Astro7Timer->new();

my %report = $w7t->get(
    product => 'astro',
    lat     => 51.2,
    lon     => -1.8,

7Timer is well known in the amateur astronomy community because it offers the "ASTRO" forecast, which includes astronomical seeing and atmospheric transparency, important aspects of a stargazing forecast. I am actually donating the servers the service runs on, and I develop a free iOS client (Xasteria) for it. It has some other forecast products, e.g. passing product => 'civil' will get you a more traditional type of forecast.

About Dimitrios Kechagias

user-pic Computer scientist, physicist, amateur astronomer.