Mojo::YR - Get weather information from yr.no
Mojo::YR is an (a)synchronous weather data fetcher for the Mojolicious framework. The backend for weather data is http://yr.no.
Look at the resources below for mere information about the API:
http://api.met.no/weatherapi/documentation
http://api.met.no/weatherapi/locationforecast/1.9/documentation
http://api.met.no/weatherapi/textforecast/1.6/documentation
http://api.met.no/weatherapi/sunrise/1.1/documentation
use Mojo::YR; my $yr = Mojo::YR->new; # Fetch location_forecast ========================================== my $now = $yr->location_forecast([59, 10])->find('pointData > time')->first; my $temp = $now->at('temperature'); warn "$temp->{value} $temp->{unit}"; # Fetch text_forecast ============================================== my $today = $yr->text_forecast->children('time')->first; my $hordaland = $today->at('area[name="Hordaland"]'); warn $hordaland->at('header')->text; warn $hordaland->at('in')->text; # "in" holds the forecast text
$hash_ref = $self->url_map;
Returns the URL used to fetch data.
Note: These will always be pointers to the current version. If you require a specific version, set it manually. Note: YR have short deprecation cycles.
Default:
{ location_forecast => 'http://api.yr.no/weatherapi/locationforecast/1.9/', text_forecast => 'http://api.yr.no/weatherapi/textforecast/1.6/', };
$self = $self->location_forecast([$latitude, $longitude], sub { my($self, $err, $dom) = @_; ... }); $self = $self->location_forecast(\%args, sub { my($self, $err, $dom) = @_; ... }); $dom = $self->location_forecast([$latitude, $longitude]); $dom = $self->location_forecast(\%args);
Used to fetch weather forecast for a specified place.
%args is required (unless [$latitude,$longitude] is given):
%args
[$latitude,$longitude]
{ latitude => $num, longitude => $num, }
$dom is a Mojo::DOM object you can use to query the result. See "SYNOPSIS" for example.
$dom
$self = $self->text_location_forecast([$latitude, $longitude], sub { my($self, $err, $dom) = @_; ... }); $self = $self->text_location_forecast(\%args, sub { my($self, $err, $dom) = @_; ... }); $dom = $self->text_location_forecast([$latitude, $longitude]); $dom = $self->text_location_forecast(\%args);
Used to fetch textual weather forecast for a specified place.
{ latitude => $num, longitude => $num, language => 'nb', # default }
$dom = $self->text_forecast(\%args); $self = $self->text_forecast(\%args, sub { my($self, $err, $dom) = @_; ... });
Used to fetch textual weather forecast for all parts of the country.
%args is optional and has these default values:
{ forecast => 'land', language => 'nb', }
$dom = $self->sunrise(\%args); $self = $self->sunrise(\%args, sub { my($self, $err, $dom) = @_; ... });
Used to fetch When does the sun rise and set for a given place
%args is required
{ lat => $num, lon => $num, date => 'YYYY-MM-DD', # OR from => 'YYYY-MM-DD', to => 'YYYY-MM-DD', }
Copyright (C) 2014 Jan Henning Thorsen
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Jan Henning Thorsen - jhthorsen@cpan.org Marcus Ramberg - mramberg@cpan.org
jhthorsen@cpan.org
mramberg@cpan.org
To install Mojo::YR, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::YR
CPAN shell
perl -MCPAN -e shell install Mojo::YR
For more information on module installation, please visit the detailed CPAN module installation guide.