summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-08-27 03:05:11 -0400
committerJesse Luehrs <doy@tozt.net>2013-08-27 03:08:22 -0400
commit4e91df75945a2390819a6243a39cd4dae7f2a3d0 (patch)
tree0b1c1227d6f24794fec4893d7054a1e19281bdcf
parent84d9f252092e05743be1efc4e9062509d30adb55 (diff)
downloadconf-4e91df75945a2390819a6243a39cd4dae7f2a3d0.tar.gz
conf-4e91df75945a2390819a6243a39cd4dae7f2a3d0.zip
display a cached version of the weather in i3bar
-rw-r--r--Makefile3
-rwxr-xr-xbin/status10
-rwxr-xr-xbin/update-weather9
-rw-r--r--crontab1
4 files changed, 21 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 86b8c03..fe7e800 100644
--- a/Makefile
+++ b/Makefile
@@ -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)/.% : %
diff --git a/bin/status b/bin/status
index 44abfba..38e0b1e 100755
--- a/bin/status
+++ b/bin/status
@@ -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);
+}
diff --git a/crontab b/crontab
new file mode 100644
index 0000000..0ea3ed9
--- /dev/null
+++ b/crontab
@@ -0,0 +1 @@
+*/15 * * * * . ~/.env && export PATH=~/.bin:$PATH && update-weather