Snippets

Brian Medley Weather bash script

Created by Brian Medley last modified
#!/bin/bash

TEMPS=$(/opt/perl -Mojo -E 'use experimental qw(postderef);' \
    -E '$j=g("http://api.wunderground.com/api/$ARGV[0]/conditions/hourly/q/TX/IAH.json")->json;' \
    -E '%temp=map({ $_->{FCTTIME}{epoch} => $_->{temp}{english} } @{ $j->{hourly_forecast} });' \
    -E '$max=0;' \
    -E '$time=time;' \
    -E 'foreach my $t (sort keys %temp) { next unless (localtime($time))[7] == (localtime($t))[7]; $temp{$max} < $temp{$t} ? $max = $t : $max };' \
    -E 'print(sprintf("%02d:%02d %s %s", (localtime($max))[2,1], $temp{$max}, $max))' $1)

set -- $TEMPS

echo $1
echo $2
echo $3

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.