| 1 | #!/usr/local/bin/perl | ||
| 2 | package main; | ||
| 3 | use strict; | ||
| 4 | use Weather::MOSMIX; | ||
| 5 | use Data::Dumper; | ||
| 6 | use charnames ':full'; | ||
| 7 | use Weather::MOSMIX; | ||
| 8 | use Time::Piece; | ||
| 9 | use Getopt::Long; | ||
| 10 | |||
| 11 | our $VERSION = '0.04'; | ||
| 12 | |||
| 13 | GetOptions( | ||
| 14 | 'latitude=s' => \my $latitude, | ||
| 15 | 'longitude=s' => \my $longitude, | ||
| 16 | 'dsn=s' => \my $dsn, | ||
| 17 | ); | ||
| 18 | |||
| 19 | $dsn ||= 'dbi:SQLite:dbname=mosmix-forecast.sqlite'; | ||
| 20 | |||
| 21 | my $w = Weather::MOSMIX->new( | ||
| 22 | dbh => { | ||
| 23 | dsn => $dsn | ||
| 24 | }, | ||
| 25 | ); | ||
| 26 | |||
| 27 | # Read location from .locationrc | ||
| 28 | # File::HomeDir | ||
| 29 | # ~/.config/.locationrc | ||
| 30 | # ~/.locationrc | ||
| 31 | $latitude //= 50.11; | ||
| 32 | $longitude //= 8.68; | ||
| 33 | |||
| 34 | my $f = | ||
| 35 | $w->forecast(latitude => $latitude, longitude => $longitude ); | ||
| 36 | my $out = $w->format_forecast( $f ); | ||
| 37 | |||
| 38 | binmode STDOUT, ':encoding(UTF-8)'; | ||
| 39 | |||
| 40 | for my $day ('today', 'tomorrow') { | ||
| 41 | my $issue = substr $out->{issuetime},0,10; | ||
| 42 | my $date = $out->{weather}->{$day}->{date}->strftime('%Y-%m-%d'); | ||
| 43 | print "$out->{location} (\x{1F321}$Weather::MOSMIX::Weathercodes::as_emoji $out->{weather}->{$day}->{min}/$out->{weather}->{$day}->{max}) ($date)\n"; | ||
| 44 | for my $w (@{ $out->{weather}->{$day}->{weather}}) { | ||
| 45 | print $w->{timestamp}, "\n"; | ||
| 46 | print sprintf "%02d %s$Weather::MOSMIX::Weathercodes::as_emoji %s\n", $w->{timestamp}->hour, $w->{description}->{emoji}, $w->{description}->{text}; | ||
| 47 | }; | ||
| 48 | |||
| 49 | # Maybe a one-line information per day, with samples/aggregates at | ||
| 50 | # 03, 09, 15 and 21 ? | ||
| 51 | }; | ||
| 52 | |||
| 53 | __END__ |