diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-08-27 03:05:11 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-08-27 03:08:22 -0400 |
commit | 4e91df75945a2390819a6243a39cd4dae7f2a3d0 (patch) | |
tree | 0b1c1227d6f24794fec4893d7054a1e19281bdcf | |
parent | 84d9f252092e05743be1efc4e9062509d30adb55 (diff) | |
download | conf-4e91df75945a2390819a6243a39cd4dae7f2a3d0.tar.gz conf-4e91df75945a2390819a6243a39cd4dae7f2a3d0.zip |
display a cached version of the weather in i3bar
-rw-r--r-- | Makefile | 3 | ||||
-rwxr-xr-x | bin/status | 10 | ||||
-rwxr-xr-x | bin/update-weather | 9 | ||||
-rw-r--r-- | crontab | 1 |
4 files changed, 21 insertions, 2 deletions
@@ -66,12 +66,13 @@ RM = @rm -f build : $(BUILD) -install : build $(INSTALLED) +install : build $(INSTALLED) /var/spool/cron/$(USER) @for dir in $(EMPTYDIRS); do mkdir -p $(INTO)/$$dir; done $(ECHO) Installed into $(INTO) clean : $(ECHO) Cleaning from $(INTO) + @crontab -d $(RM) $(BUILD) $(INSTALLED) $(INTO)/.% : % @@ -19,7 +19,15 @@ while (<$i3status>) { my ($up, $down) = map { human_bytes(net_rate($iface, $_)) } 'rx', 'tx'; $item->{full_text} =~ s{^($iface:)}{sprintf("%s %6s/%6s", $1, $up, $down)}e; } + + my $weather_file = "$ENV{HOME}/.weather"; + if (-r $weather_file && -f $weather_file) { + my $weather = slurp($weather_file); + unshift @$line, { name => 'weather', full_text => $weather }; + } + unshift @$line, { name => 'title', full_text => get_title() }; + say(($comma ? ',' : ''), encode_json($line)); } @@ -75,7 +83,7 @@ sub human_bytes { } sub slurp { - open my $fh, '<', $_[0] or die "Couldn't open $_[0]: $!"; + open my $fh, '<:encoding(UTF-8)', $_[0] or die "Couldn't open $_[0]: $!"; if (wantarray) { <$fh> } diff --git a/bin/update-weather b/bin/update-weather new file mode 100755 index 0000000..e5dd5a2 --- /dev/null +++ b/bin/update-weather @@ -0,0 +1,9 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Path::Class; + +if (my $weather = `weather`) { + file("$ENV{HOME}/.weather")->openw->print($weather); +} @@ -0,0 +1 @@ +*/15 * * * * . ~/.env && export PATH=~/.bin:$PATH && update-weather |