summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING6
-rwxr-xr-xbin/vweather147
l---------share/weather/chance_of_rain1
-rw-r--r--share/weather/clouds.pngbin0 -> 581 bytes
-rw-r--r--share/weather/clouds_40.pngbin0 -> 634 bytes
l---------share/weather/cloudy1
-rw-r--r--share/weather/cloudy.pngbin0 -> 694 bytes
-rw-r--r--share/weather/cloudy_40.pngbin0 -> 781 bytes
-rw-r--r--share/weather/lightning.pngbin0 -> 641 bytes
-rw-r--r--share/weather/lightning_40.pngbin0 -> 699 bytes
l---------share/weather/mostly_sunny1
-rw-r--r--share/weather/rain.pngbin0 -> 665 bytes
-rw-r--r--share/weather/rain_40.pngbin0 -> 683 bytes
-rw-r--r--share/weather/snow.pngbin0 -> 341 bytes
-rw-r--r--share/weather/snow_40.pngbin0 -> 409 bytes
-rw-r--r--share/weather/sun.pngbin0 -> 623 bytes
-rw-r--r--share/weather/sun_40.pngbin0 -> 719 bytes
l---------share/weather/sunny1
18 files changed, 157 insertions, 0 deletions
diff --git a/COPYING b/COPYING
index b764540..87652e2 100644
--- a/COPYING
+++ b/COPYING
@@ -10,3 +10,9 @@ This file is part of the Crystal Icon Set, licensed under the terms of the GPL.
Please see
<http://www.everaldo.com/crystal/> and
<http://www.everaldo.com/crystal/?action=license>
+
+
+ share/weather_*
+
+Parts of the Silk icon set, licensed CC-BY.
+Please see <http://famfamfam.com/lab/icons/silk/>
diff --git a/bin/vweather b/bin/vweather
new file mode 100755
index 0000000..06f6461
--- /dev/null
+++ b/bin/vweather
@@ -0,0 +1,147 @@
+#!/usr/bin/env perl
+## Copyright © 2011 by Daniel Friesel <derf@finalrewind.org>
+## License: WTFPL:
+## 0. You just DO WHAT THE FUCK YOU WANT TO.
+use strict;
+use warnings;
+use 5.010;
+use autodie;
+
+use GD;
+use Getopt::Std;
+use Term::ANSIColor;
+use Weather::Google;
+
+my %opt;
+my $alpha;
+my $dump;
+my $share = $0;
+
+my $weather = Weather::Google->new(
+ 'Essen, Germany',
+ {
+ language => 'de',
+ },
+);
+
+my $forecasts = $weather->forecast_conditions();
+
+
+sub show_weather_console {
+ for my $day(@{$forecasts}) {
+ printf(
+ "%-6s %s%3d°c%s %s%3d°c%s %s\n",
+ $day->{'day_of_week'},
+ color('blue'),
+ $day->{'low'},
+ color('reset'),
+ color('red'),
+ $day->{'high'},
+ color('reset'),
+ $day->{'condition'},
+ );
+
+ if ($dump) {
+ say $day->{'icon'};
+ }
+ }
+}
+
+sub show_weather_png {
+ my ($w, $h) = (140, 64);
+ my $im = GD::Image->new($w, $h);
+
+ my $white = $im->colorAllocateAlpha(255, 255, 255, $alpha);
+ my $blue = $im->colorAllocateAlpha( 0, 0, 200, $alpha);
+ my $red = $im->colorAllocateAlpha(200, 0, 0, $alpha);
+ my $gray = $im->colorAllocateAlpha(127, 127, 127, $alpha);
+ my $black = $im->colorAllocateAlpha( 0, 0, 0, $alpha);
+
+ $im->filledRectangle(1, 1, $w - 2, $h - 2, $white);
+
+ for my $i (0..3) {
+ my $offset = $i * 16;
+ my $day = $forecasts->[$i];
+
+ my $wday = substr($day->{'day_of_week'}, 0, 2);
+ my $low = sprintf('%3dc', $day->{'low'});
+ my $high = sprintf('%3dc', $day->{'high'});
+ my ($icon) = ($day->{'icon'} =~ m{ / ([^/]+) \. gif $ }x);
+
+ if (not defined $day) {
+ last;
+ }
+
+ $im->string(gdMediumBoldFont, 10, $offset, $wday , $black);
+ $im->string(gdMediumBoldFont, 60, $offset, $low , $blue);
+ $im->string(gdMediumBoldFont, 95, $offset, $high , $red);
+
+ if ($dump) {
+ say "${share}/weather/${icon}";
+ }
+
+ if (-e "${share}/weather/${icon}") {
+ my $tmp = GD::Image->newFromPng("${share}/weather/${icon}", 1);
+ $im->copy($tmp, 40, $offset, 0, 0, 16, 16);
+ }
+ }
+
+ $im->rectangle(0, 0, $w -1, $h -1, $gray);
+
+ open(my $out_fh, '>', '/tmp/vweather.png');
+ binmode $out_fh;
+ print $out_fh $im->png();
+ close($out_fh);
+}
+
+getopts('a:cdfg', \%opt);
+$alpha = $opt{'a'} // 40;
+$dump = $opt{'d'} // 0;
+
+if (-l $share) {
+ my $link = readlink($share);
+ $share =~ s{ [^/]+ $ }{}x;
+ $link =~ s{ / bin / vweather $ }{}x;
+ $share .= "${link}/share";
+}
+else {
+ $share =~ s{ / bin / vweather $ }{}x;
+ $share .= '/share';
+}
+
+if ($opt{'c'}) {
+ show_weather_console();
+}
+elsif ($opt{'g'}) {
+ show_weather_png();
+}
+
+if ($opt{'f'}) {
+ exec('feh', '/tmp/vweather.png');
+}
+
+__END__
+
+=head1 NAME
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 OPTIONS
+
+=head1 EXIT STATUS
+
+=head1 CONFIGURATION
+
+=head1 DEPENDENCIES
+
+=head1 BUGS AND LIMITATIONS
+
+=head1 AUTHOR
+
+Copyright (C) 2011 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt>
+
+=head1 LICENSE
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
diff --git a/share/weather/chance_of_rain b/share/weather/chance_of_rain
new file mode 120000
index 0000000..5b36e83
--- /dev/null
+++ b/share/weather/chance_of_rain
@@ -0,0 +1 @@
+rain_40.png \ No newline at end of file
diff --git a/share/weather/clouds.png b/share/weather/clouds.png
new file mode 100644
index 0000000..3f73eaa
--- /dev/null
+++ b/share/weather/clouds.png
Binary files differ
diff --git a/share/weather/clouds_40.png b/share/weather/clouds_40.png
new file mode 100644
index 0000000..8503e8f
--- /dev/null
+++ b/share/weather/clouds_40.png
Binary files differ
diff --git a/share/weather/cloudy b/share/weather/cloudy
new file mode 120000
index 0000000..f7ae88d
--- /dev/null
+++ b/share/weather/cloudy
@@ -0,0 +1 @@
+clouds_40.png \ No newline at end of file
diff --git a/share/weather/cloudy.png b/share/weather/cloudy.png
new file mode 100644
index 0000000..5856e1d
--- /dev/null
+++ b/share/weather/cloudy.png
Binary files differ
diff --git a/share/weather/cloudy_40.png b/share/weather/cloudy_40.png
new file mode 100644
index 0000000..3993ab1
--- /dev/null
+++ b/share/weather/cloudy_40.png
Binary files differ
diff --git a/share/weather/lightning.png b/share/weather/lightning.png
new file mode 100644
index 0000000..1d42b36
--- /dev/null
+++ b/share/weather/lightning.png
Binary files differ
diff --git a/share/weather/lightning_40.png b/share/weather/lightning_40.png
new file mode 100644
index 0000000..85b280f
--- /dev/null
+++ b/share/weather/lightning_40.png
Binary files differ
diff --git a/share/weather/mostly_sunny b/share/weather/mostly_sunny
new file mode 120000
index 0000000..d1cf0f7
--- /dev/null
+++ b/share/weather/mostly_sunny
@@ -0,0 +1 @@
+cloudy_40.png \ No newline at end of file
diff --git a/share/weather/rain.png b/share/weather/rain.png
new file mode 100644
index 0000000..e6072cc
--- /dev/null
+++ b/share/weather/rain.png
Binary files differ
diff --git a/share/weather/rain_40.png b/share/weather/rain_40.png
new file mode 100644
index 0000000..2207d7b
--- /dev/null
+++ b/share/weather/rain_40.png
Binary files differ
diff --git a/share/weather/snow.png b/share/weather/snow.png
new file mode 100644
index 0000000..45bbdf1
--- /dev/null
+++ b/share/weather/snow.png
Binary files differ
diff --git a/share/weather/snow_40.png b/share/weather/snow_40.png
new file mode 100644
index 0000000..a86de75
--- /dev/null
+++ b/share/weather/snow_40.png
Binary files differ
diff --git a/share/weather/sun.png b/share/weather/sun.png
new file mode 100644
index 0000000..0156c26
--- /dev/null
+++ b/share/weather/sun.png
Binary files differ
diff --git a/share/weather/sun_40.png b/share/weather/sun_40.png
new file mode 100644
index 0000000..12bcb46
--- /dev/null
+++ b/share/weather/sun_40.png
Binary files differ
diff --git a/share/weather/sunny b/share/weather/sunny
new file mode 120000
index 0000000..a721871
--- /dev/null
+++ b/share/weather/sunny
@@ -0,0 +1 @@
+sun_40.png \ No newline at end of file