| 1 | #!/usr/local/bin/perl | ||
| 2 | package main; | ||
| 3 | use strict; | ||
| 4 | use Weather::MOSMIX; | ||
| 5 | use Weather::MOSMIX::Weathercodes 'mosmix_weathercode'; | ||
| 6 | use Data::Dumper; | ||
| 7 | use charnames ':full'; | ||
| 8 | use Time::Piece; | ||
| 9 | use Text::Table; | ||
| 10 | use Getopt::Long; | ||
| 11 | |||
| 12 | our $VERSION = '0.04'; | ||
| 13 | |||
| 14 | GetOptions( | ||
| 15 | 'latitude=s' => \my $latitude, | ||
| 16 | 'longitude=s' => \my $longitude, | ||
| 17 | 'dsn=s' => \my $dsn, | ||
| 18 | ); | ||
| 19 | |||
| 20 | $dsn ||= 'dbi:SQLite:dbname=mosmix-forecast.sqlite'; | ||
| 21 | |||
| 22 | my $w = Weather::MOSMIX->new( | ||
| 23 | dbh => { | ||
| 24 | dsn => $dsn | ||
| 25 | }, | ||
| 26 | ); | ||
| 27 | # Read location from .locationrc | ||
| 28 | # File::HomeDir | ||
| 29 | # ~/.config/.locationrc | ||
| 30 | # ~/.locationrc | ||
| 31 | |||
| 32 | $latitude //= 50.11; | ||
| 33 | $longitude //= 8.68; | ||
| 34 | |||
| 35 | my $f = | ||
| 36 | $w->forecast_dbh(latitude => $latitude, longitude => $longitude ); | ||
| 37 | my $out = $w->format_forecast_dbh( $f, 6 ); | ||
| 38 | |||
| 39 | my @output; | ||
| 40 | |||
| 41 | # print the header | ||
| 42 | push @output, [map { ' ' . $out->[ $_ * 4 ]->{weekday} } 0..2]; | ||
| 43 | |||
| 44 | for my $row (0..3) { | ||
| 45 | #print $out->[$row]->{status}, " "; | ||
| 46 | my $outrow = []; | ||
| 47 | for my $col (0..2) { | ||
| 48 | my $elt = $out->[ $row + $col*4 ]; | ||
| 49 | if( $elt->{status} eq 'active' ) { | ||
| 50 | push @$outrow, sprintf "%2.0f/%2.0f\x{1F321}$Weather::MOSMIX::Weathercodes::as_emoji %s", $elt->{mintemp}-273.15, $elt->{maxtemp}-273.15, $elt->{emoji} | ||
| 51 | } else { | ||
| 52 | push @$outrow, " -/- "; | ||
| 53 | } | ||
| 54 | }; | ||
| 55 | push @output, $outrow; | ||
| 56 | } | ||
| 57 | |||
| 58 | binmode STDOUT, ':encoding(UTF-8)'; | ||
| 59 | my $t = Text::Table->new( @{ shift @output } ); | ||
| 60 | $t->load( @output ); | ||
| 61 | print $out->[0]->{description},"\n"; | ||
| 62 | print $t; | ||
| 63 | |||
| 64 | __END__ |