dwm
google
♥ perl

if your terminal does not support unicode (I just discovered that PM code blocks do not...), consider changing the i subroutine to be something more visible

#!/usr/bin/perl -w use strict; use encoding 'utf8'; use Weather::Google; use Math::Units qw/convert/; my $LOCATION = "Nowhere"; # set to city name or postal code my $gw = new Weather::Google($LOCATION); # single-character icons for weather conditions # returns one string with one icon per argument sub i { my $i=''; $i .= /sun/i ? chr 0x2600 : /cloud/i ? chr 0x2601 : /rain|shower/i ? chr 0x2602 : /snow/i ? '*': $_ foreach @_; # the above regexes probably don't cover ALL conditions # but they do cover the ones I have seen over the past few days return $i } # format a temperature # originally the second argument was $f but I found that # I had to convert the temperature much more than I had to # not convert the temperature. If you are one of those types # that thinks in non-SI units, you might want to change that. sub t { my ($t, $c) = @_; return int($c ? $t : convert($t,'F','C')) . chr 0x00b0; } print '[', t($gw->temp_c,1), '(',t($gw->forecast(0,'high')), '/', t($gw->forecast(0,'low')), ')', i($gw->forecast(0,'condition')), '|', i($gw->forecast(1,'condition')), t($gw->forecast(1,'high')), '/', t($gw->forecast(1,'low')), ']';

The above script produces something like [17°(18°/5°)|23°/11°] A newline is omitted because the script's output is combined with other scripts' outputs to create a single string of statuses and notifications. If you want to run it alone on the command line, I suggest adding ;echo to the end of your invocation.

Thanks to Daniel LeWarne for the module!


$,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
Happy, sober, smart: pick two.

In reply to Google Weather for dwm by xyzzy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.