Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Conky Weather Script

by stuffy (Monk)
on May 07, 2008 at 22:02 UTC ( #685337=CUFP: print w/replies, xml ) Need Help??

Here is a script that I modified (the original is from the example in Geo::METAR) that feeds a line of weather data to a Conky (software) script running on my linux box.

#!/usr/bin/perl -w # Get the site code. my $site_code = shift @ARGV; die "Usage: $0 <site_code>\n" unless $site_code; # Get the modules we need. use Data::Dumper; use Geo::METAR; use LWP::UserAgent; use strict; my $ua = new LWP::UserAgent; my $req = new HTTP::Request GET => "$site_code"; my $response = $ua->request($req); if (!$response->is_success) { print $response->error_as_HTML; my $err_msg = $response->error_as_HTML; warn "$err_msg\n\n"; die "$!"; } else { # Yep, get the data and find the METAR. my $m = new Geo::METAR; $m->debug(0); my $data; $data = $response->as_string; # grap response $data =~ s/\n//go; # remove newlines $data =~ m/($site_code\s\d+Z.*?)</go; # find the METAR strin +g my $metar = $1; # keep it # Sanity check if (length($metar)<10) { die "METAR is too short! Something went wrong."; } # pass the data to the METAR module. $m->metar($metar); # Here we will take the information from the module and put it into ou +r variables. my $f_temp = int($m->TEMP_F) ; my $time = $m->TIME; my @sky_conds= @{$m->SKY()}; my $wind = int($m->WIND_MPH); my $w_dir = $m->WIND_DIR_ENG; my $gust = $m->WIND_GUST_MPH; my $vis =$m->VISIBILITY; my @cur_weather = @{$m->WEATHER()}; my $dew = $m->F_DEW; my $bar = $m->ALT; my $tz_adjust = -4; #to adjust the time zone so that the metar dat +a is in local time. #lets play with the time a litte bit now $time =~s/UTC//go; $vis =~s/Statute//go; my $hours; my $minutes; ($hours, $minutes) = ($time =~ /(\d\d):(\d\d)/); my $local_hours = ($hours + $tz_adjust); #now we need to see if the wind is gusting my $gusting; if ($gust) { $gusting =", gusting to $gust mph | "; } else { $gusting =" | "; } #the program wouldn't be any good without some here it is. print "Conditions as of $local_hours:$minutes |"; print " @sky_conds "; print "$f_temp Degrees "; if (@cur_weather) { print "@cur_weather | "; } else{ print "| "; } print "visibility is $vis | $w_dir winds blowing at $wind mph"; print "$gusting"; print "barometer at $bar inches \n"; print @cur_weather; } # end else exit; __END__

and the conkyrc file that uses it is
#avoid flicker double_buffer yes #own window to run simultanious 2 or more conkys own_window yes own_window_transparent no own_window_type normal own_window_hints undecorate,sticky,skip_taskbar,skip_pager #borders draw_borders no border_margin 1 #shades draw_shades no #position gap_x 6 gap_y 6 alignment top_left #behaviour update_interval 900 #colour default_color 8f8f8f #default_shade_color 000000 own_window_colour 262626 #font use_xft yes xftfont bauhaus:pixelsize=10 #to prevent window from moving use_spacer no minimum_size 1268 0 #mpd TEXT ${voffset -1} ${color white}${font Liberation Sans:style=Bold:size=10 +}${execi 300 perl ~/perl/ KISP}
update: * Just wanted to post a screen shot for everyone to see. the weather conky is the black bar across the top of the screen I would like to test the @cur_weather the same way I test for $gusting, so that my output section is a little neater, but I haven't figured that out yet. I need to fix the time zone dosnt' work between 0:00 and 03:59 UTC. I want to change the sky condition print out so that it only prints out the most important information. Thanks to the guys in the chatter box for helping me figure out some things.

That's my story, and I'm sticking to it, unless I'm wrong in which case I will probably change it ;~)
may be reproduced under the SDL

Replies are listed 'Best First'.
Re: Conky Weather Script
by chanio (Priest) on May 23, 2008 at 05:10 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://685337]
Approved by ww
Front-paged by Arunbear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-10-17 18:26 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (72 votes). Check out past polls.