![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
Hello, Unregistered You are browsing a READ only archive of the main support categories pre 4/21/2008. You will not be able to post or reply any threads in this section.
Ubuntu 9.10 is out!!!
When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu. The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely. |
|
Desktop Effects & Customization This section is for all your compositing needs. This includes Beryl, Compiz, xcompmgr, and other fancy apps which take advantage of compositing managers such as kiba-dock and avant window decorator |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Has an Ubuntu Drip
![]() Join Date: Jul 2006
Beans: 704
Ubuntu 9.04 Jaunty Jackalope
|
Conky Weather Revisited V2
IMPORTANT: Before using the new script be aware that the options have changed ( 03 Feb 08 ), and your conkyrc will most likely need to be updated.
The original Conky Weather Revisited was too buggy, because of the way Conky handles bash. Still don't know why it is different, but I decided I would write the script in a language I was more familiar with anyway. So I wrote the V2 in perl. I hope that everyone likes what I have done. I will try my best to meet everyone's needs. Well, I didn't really like the other conky weather scripts that were out there. They just didn't do what I wanted and were too complicated, so I made my own. I hope everyone likes it. Step 0: Find your city code. You can go to weather.com and put in your city in the search. It will then ask you to select the city that you meant. Select that, once the page has loaded look at the address bar for a number after the last / (it should include letters too). Step 1: This conky setup uses a weather font, which I have attached. To install the fonts follow the directions below. 1. Make the following directory as root: Code:
# sudo mkdir /usr/share/fonts/truetype/myfonts Code:
# sudo cp [fonts] /usr/share/fonts/truetype/myfonts Code:
# fc-cache -f -v Code:
#!/usr/bin/perl
use Switch;
use Encode;
use Text::Wrap;
# This script was written by lvleph and inspired by the original conky weather script written by azhag (azhag@bsd.miki.eu.org)
# Modyfied by LazarusHC to list more details
$code=$ARGV[0]; #zipcode or weather.com city code
$system=$ARGV[1]; #f for imperial c for metric
$what=$ARGV[2]; #what are we looking for?
$file="/tmp/weather.html"; #temp holding weather
$update=3600; #time in seconds to update $file if set to 0 don't use $file
$leadspace=" "; #spacing before each high low
$trailspace=" "; #spacing after each high low.
$fspaces=""; #spacing between condition symbols.
$dspaces=" "; #spacing between each day
$lines="\n\n\n\n"; #each \n represents one line between the days and temps
$Text::Wrap::columns = 58;
$initial_tab=""; #tab before first line in weather output
$subsequent_tab="\t"; #tab before each subsequet line in weather output
$degree= encode_utf8( "\x{00B0}" ); #give me the degree symbol, not everyone has same locale
#ensure user inputs proper system
if($system !=~ "c" || $system !=~ "f"){$what=0;} #this will give usage error
switch($what){ #determine what user wants
case "c" { #if current conditions
&file_op; #save weather to $file
while(<FILE>){ #cycle through file
if (/<em>Current conditions/ .. /<h3>/){ #found current conditions
($cn2) = /<h3>(\b.+\b)<\/h3>/; #save current conditions
if($cn2){print "$cn2\n"; exit;}
}
}
}
case "w" { #if list
&file_op; #save weather to file
while(<FILE>){ #cycle through file
if (/<dt>Feels Like:<\/dt>/ .. /<dd>/){ #found feels like temp
($tmf) = /<dd>(-?\d+)/; #sav temp
}
if (/<dt>Humidity:<\/dt>/ .. /<dd>/){ #found current humidity
($hmt) = /<dd>(\d+\%)/; #save current humidity
}
if (/<dt>Wind:<\/dt>/ .. /<dd>/){ #found wind conditions
($wnd) = /<dd>(\b.+\b)<\/dd>/; #save wind conditions
#do we have current conditions?
if($tmf && $hmt && $wnd){
print "Feels like: $tmf$degree\n";
print "Humidity: $hmt\n";
print "Wind: $wnd\n"; exit;}
}
}
}
case "cp" { #if current conditions symbol
&file_op; #save weather to $file
while(<FILE>){ #cycle through file
if (/<em>Current conditions/ .. /<h3>/){ #found current conditions
($cnd) = /<h3>(\b.+\b)<\/h3>/; #save current conditions
#do we have current conditions? Then translate into symbol
if($cnd){cond_symb($cnd); print "$ctext\n"; exit;}
}
}
}
case "t" { #if current temp
&file_op; #save weather to $file
while(<FILE>){ #cycle through file
if (/<div id="forecast-temperature">/ .. /<h3>/){ #found current temp
($tmp) = /<h3>(-?\d+)/; #save current temp
#do we have current temp? Then print
if($tmp){print "$1$degree\n"; exit;}
}
}
}
case /[1-5]d$/ { #display the days up to specified day
&file_op; #save weather to $file
my $day=(split "t", $what)[0]; #how many days are we looking for
my $count=0;
while(<FILE>){
if(/<th>(\b.+\b)<\/th>/ && ++$count<=$day){ #look for the conditions upto specified day
$days[$count-1]=$1; #save day
&day_space($days);
}
elsif($count>=$day){print "$dtext\n"; exit;} #don't keep lopking if everything has been found
}
}
case /[1-5]dp$/ { #display the conditions from today through day $days
&file_op; #save weather to $file
my $day=(split "p", $what)[0]; #how many days are we looking for
my $flag=0; #set flag for when we find start of conditions
my $count=0;
while(<FILE>){
if(/^<tr class="titles">\s*$/){$flag=1;} #found the start of conditions
elsif($flag && /(\b.+\b)<\/td>/ && ++$count<=$day){ #look for the conditions upto specified day
$cnd[$count-1]=$1; #save conditions
&cond_symb ($cnd[$count-1]); #translate conditions to symbol
#exit;
}
elsif($count>=$day){print "$ctext\n"; exit;} #don't keep looking if everything has been found
}
}
case /[1-5]t$/ { #display the temps from today through day $days
&file_op; #save weather to $file
my $count=0;
my $day=(split "t", $what)[0]; #how many days are we looking for
while(<FILE>){
#get the high temp
(my $high) = /<td><strong>High: (-?\d+)°<\/strong><span>Low: \-?\d+°<\/span><\/td>/;
#get the low temp
(my $low) = /<td><strong>High: \-?\d+°<\/strong><span>Low: (-?\d+)°<\/span><\/td>/;
#print the high and low temp for the specified day
if($high=~/\d+/ && $low=~/\d+/ && ++$count<=$day){print "$leadspace$high$degree/$low$degree$trailspace";}
elsif($count>=$day){print "\n"; exit;} #don't keep looking if everything has been found
}
}
case /[1-5]dt$/ {
&file_op; #save weather to $file
my $count1 = my $count2=0;
my $day=(split "dt", $what)[0]; #how many days are we looking for
my $flag=1; #print days once
while(<FILE>){
#get the high temp
(my $high) = /<td><strong>High: (-?\d+)°<\/strong><span>Low: \-?\d+°<\/span><\/td>/;
#get the low temp
(my $low) = /<td><strong>High: \-?\d+°<\/strong><span>Low: (-?\d+)°<\/span><\/td>/;
#print the high and low temp for the specified day
if(/<th>(\b.+\b)<\/th>/ && ++$count1<=$day){ #look for the conditions upto specified day
$days[$count1-1]=$1; #save day
&day_space($days);
}
elsif($high=~/\d+/ && $low=~/\d+/ && ++$count2<=$day){$ttext.=$leadspace.$high.$degree."/".$low.$degree.$trailspace;}
elsif($count1>=$day && $count2>=$day){print "$dtext\n$lines$ttext\n"; exit;} #don't keep lopking if everything has been found
}
}
case /[1-7]w$/ { #display the weather forecast in words from today through day $days
&file_op; #save weather to $file
my $num=(split "w", $what)[0]; #how many are we looking for
my $count=0; #initialize count
while(<FILE>){ #cycle through file
#get the weather
(my $when) = /<li><strong>(\b.+\b\:)<\/strong>/;
(my $weather) = /<\/strong>(.+)<\/li>/;
$weather=$when.$weather;
#print weather
if($when && ++$count<=$num){
#print "$when";
print wrap($initial_tab, $subsequent_tab, $weather);
print "\n";
}
elsif($count>=$num){exit;} #don't keep looking if everything has been found
}
}
case /[1-5]p$/ { #if conditions of specified day
&file_op; #save weather to $file
my $day=(split "p", $what)[0]; #what day are we looking for
my $flag=0; #set flag for when we find start of conditions
my $count=0;
while(<FILE>){
if(/^<tr class="titles">\s*$/){$flag=1;} #found the start of conditions
elsif($flag && /(\b.+\b)<\/td>/ && ++$count==$day){ #look for the conditions for specified day
$cnd=$1; #save conditions
&cond_symb ($cnd); #translate conditions to symbol
}
elsif($count>=$day){print "$ctext\n"; exit;} #don't keep looking if everything has been found
}
}
case /[1-5]$/ { #if temp of specified day
&file_op; #save weather to $file
while(<FILE>){
#get the high temp
($high) = /<td><strong>High: (-?\d+)°<\/strong><span>Low: \-?\d+°<\/span><\/td>/;
#get the low temp
($low) = /<td><strong>High: \-?\d+°<\/strong><span>Low: (-?\d+)°<\/span><\/td>/;
#print the high and low temp for the specified day
if($high && $low && ++$count==$what){print "$high$degree/$low$degree\n";}
}
}
else { #didn't give proper options
&usage; #print usage error
}
}
#print "\n"; # need endline to make things look nice
close FILE;
sub file_op { #do file operations
if(-e $file ){ #does the file exist and is not empty?
my $size=`stat -c %s $file`;
if($size >= 1000){
my $date=`date -u +%s`; #get current date in seconds
my $created=`stat -c %Y $file`; #get creation date of file in seconds
$age=$date - $created; #determine age of file
}
else{
$age=$update+1;
}
}
else{ #if file doesn't exist make it and set to update the file
`touch $file`;
$age=$update+1;
}
if ($age>=$update){ #only get a new file every hour
#obtain the weather forecast and store it in $file
`wget -O - http://weather.yahoo.com/forecast/"$code"_"$system".html > $file`;
}
open(FILE, $file) or die "Could not open file $file: $!\n";
}
sub usage { #if correct options haven't been passed usage error
print "Usage error weather.pl <citycode> <system> <option>\n";
print "weather.pl <citycode> <system> <option>\n";
print "\t<citycode> - weather.com city code\n";
print "\t<system> - c for metric or f for imperial\n";
print "\t<option> - Only one option can be entered at a time\n";
print "\t\tc displays current conditions\n";
print "\t\tw displays list of current conditions\n";
print "\t\tcp displays current conditions symbol\n";
print "\t\tt displays current temp in chosen system\n";
print "\t\t[1-5]d displays the days up to specified day\n";
print "\t\t[1-5]dp displays condition symbol for days up to specified day\n";
print "\t\t[1-5]t displays high/low temp in chosen system up to specified day\n";
print "\t\t[1-5]dt displays days and then high/low temp in chosen system up to specified day\n";
print "\t\t[1-7]w displays the weather in words up number specified\n";
print "\t\t[1-5]p displays conditions for specified day\n";
print "\t\t[1-5] displays high/low temp in chosen system for specified day\n";
}
sub cond_symb { #translates conditions into symbol in weather font
if ($_ =~ "Partly Cloudy"){$_="c";}
elsif ($_ =~ "Fair" || $_ =~ "Sun" || $_ =~ "Clear"){$_="A";}
elsif ($_ =~ "Cloud" || $_ =~ "Fog"){$_="e";}
elsif ($_ =~ "Storm" || $_ =~ "Thunder" || $_ =~ "T-"){$_="i";}
elsif ($_ =~ "Snow" || $_ =~ "Flurries" || $_ =~ "Wintry"){$_="k";}
elsif ($_ =~ "Rain" || "Drizzle"){$_="h";}
elsif ($_ =~ "Shower"){$_="g";}
$ctext.=$_.$fspaces;
}
sub day_space { #Adds spaces for aligment
if ($_ =~ "Today"){$_=" Today ";}
elsif ($_ =~ "Tonight"){$_="Tonight";}
elsif ($_ =~ "Tomorrow"){$_="Tomorrow";}
elsif ($_ =~ "Thu"){$_=" Thu ";}
elsif ($_ =~ "Fri"){$_=" Fri ";}
elsif ($_ =~ "Sat"){$_=" Sat ";}
elsif ($_ =~ "Sun"){$_=" Sun ";}
elsif ($_ =~ "Mon"){$_=" Mon ";}
elsif ($_ =~ "Tue"){$_=" Tue ";}
elsif ($_ =~ "Wed"){$_=" Wed ";}
$dtext.=$_.$dspaces;
}
Code:
weather.pl <citycode> <system> <option>
<citycode> - weather.com city code
<system> - c for metric or f for imperial
<option> - Only one option can be entered at a time
c displays current conditions
w displays list of current conditions
cp displays current conditions symbol
t displays current temp in chosen system
[1-5]d displays the days up to specified day
[1-5]dp displays condition symbol for days up to specified day
[1-5]t displays high/low temp in chosen system up to specified day
[1-5]dt displays days and then high/low temp in chosen system up to specified day
[1-7]w displays the weather in words up number specified
[1-5]p displays conditions for specified day
[1-5] displays high/low temp in chosen system for specified day
Code:
weather.pl USVA0652 f 5dp Code:
sudo chmod a+x ~/scripts/weather.pl Step 4: Use the following code for your conky file, changing "USVA0652" for your city code or ZIP code if you live in the USA, Replace "f" with "c" if you want metric degrees. Code:
# UBUNTU-CONKY.
# Update interval in seconds
update_interval 1.0
# Create own window instead of using desktop (required in nautilus)
own_window yes
own_window_type override #try also 'normal' or 'desktop'
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes
# Minimum size of text area
#minimum_size 250 5
maximum_width 250
draw_shades no
draw_outline no # amplifies text if yes
draw_borders no
draw_graph_borders no
use_xft yes
xftalpha 0.9
xftfont Candera:size=6
uppercase no
override_utf8_locale yes
use_spacer no
stippled_borders 3
border_margin 9
border_width 10
# Gap between borders of screen and text
gap_x 10
gap_y 10
# Default colors and also border colors, grey90 == #e5e5e5
default_color grey
color1 orange
# Text alignment, other possible values are commented
#alignment top_left
alignment top_right
#alignment bottom_left
#alignment bottom_right
# stuff after 'TEXT' will be formatted on screen
TEXT
${color1}$hr
${voffset -3}$alignc CURRENT CONDITIONS
${voffset -7}$hr $color
${execi 3600 perl ~/scripts/weather.pl USVA0652 f w}
${voffset -30}$alignr${offset -50}${execi 3600 perl ~/scripts/weather.pl USVA0652 f t}
${voffset -15}$alignr${offset -60}${font weather:size=45}${execi 3600 perl ~/scripts/weather.pl USVA0652 f cp}$font
${voffset -10}${color1}$hr
${voffset -3}$alignc 5 DAY FORECAST
${voffset -7}$hr $color
${font weather:size=45}${execi 3600 perl ~/scripts/weather.pl USVA0652 f 5dp}${font}$color
${voffset -55}${execi 3600 perl ~/scripts/weather.pl USVA0652 f 5dt}
${execi 3600 perl ~/scripts/weather.pl USVA0652 f 7w}
The width for the list of weather for each day can be controlled using the $Text::Wrap::columns variable (line 23). The number represent the number of columns. The tab for each days initial line can be controlled with the $initial_tab variable (line 24), where /t represents a tab. Following line tabs can be controlled with $subsequent_tab variable. NOTE 1: If the degree symbol is not printing correctly, it is most likely due to the font you are using. NOTE 2: This script is very dependent on the html tagging used by weather.com, so when they change that tagging this script won't work any more. However, I plan on staying on top of things like that. Just post here if you have any issues. NOTE 3: Please, give me feed back and let me know what you think would be a useful addition. I would like this script to be the end all of conky weather scripts. My main philosophy is to keep everything simple. I don't want to have outside dependencies, if I can help it. Note 4:You should have Code:
use_xft yes Note 5:The text weather given by the option [1-7]w is only available in the imperial system. UPDATE: 21 January 2008 Added the ability to print multi-day forecast with just two script runs; one for conditions and one for high/low. Also, added UTF-8 for the degree symbol. UPDATE: 22 January 2008 Added the ability to put spaces between condition symbols. UPDATE: 03 February 2008 Added the ability to see weather report for next 5 days, combined the days and temps into one script call (can still use the single calls), added list of current weather, added leading and trailing space for temps, and added wintry mix. UPDATE: 12 February 2008 Added Fog as cloudy and Drizzle as Rain. Thanks LazarusHC for your additions. Last edited by lvleph; February 23rd, 2008 at 10:29 PM.. |
|
|
|
|
|
#2 |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Sep 2007
Location: 34°35'S - 58°21'W
My beans are hidden!
|
Re: Conky Weather Revisited V2
Hi lvleph
I'm here, got your heads up, will check this out later, now I'm going to watch a movie with my wife. Thanks Bruce
__________________
|
|
|
|
|
|
#3 |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Sep 2007
Location: 34°35'S - 58°21'W
My beans are hidden!
|
Re: Conky Weather Revisited V2
Hi lvleph
I have my first weather.pl conky working. Looks good too, but a little heavy on CPU usage. I made some "format" changes, weather symbols are smaller and then spaced to fit over the high/lows better: Code:
${color cyan}$hr$color
${voffset -3}${alignc}${color orange}${font :size=10}Buenos Aires 5 Day Forcast$font$color
${voffset -5}${font weather:size=30}${alignc}${offset -45}${execi 3600 perl ~/scripts/lvlephw2.pl ARBA0009 c 1p}${offset 25}${color orange}${execi 3600 perl ~/scripts/lvlephw2.pl ARBA0009 c 2p}${offset 25}${color cyan}${execi 3600 perl ~/scripts/lvlephw2.pl ARBA0009 c 3p}${offset 24}${color green}${execi 3600 perl ~/scripts/lvlephw2.pl ARBA0009 c 4p}${offset 23}${color red}${execi 3600 perl ~/scripts/lvlephw2.pl ARBA0009 c 5p}${font}$color
${alignc}${offset -15}${execi 3600 perl ~/scripts/lvlephw2.pl ARBA0009 c 1}${offset 10}${execi 3600 perl ~/scripts/lvlephw2.pl ARBA0009 c 2}${offset 10}${execi 3600 perl ~/scripts/lvlephw2.pl ARBA0009 c 3}${offset 10}${execi 3600 perl ~/scripts/lvlephw2.pl ARBA0009 c 4}${offset 10}${execi 3600 perl ~/scripts/lvlephw2.pl ARBA0009 c 5}
${color cyan}$hr$color
__________________
Last edited by Bruce M.; January 14th, 2008 at 01:25 PM.. |
|
|
|
|
|
#4 |
|
Has an Ubuntu Drip
![]() Join Date: Jul 2006
Beans: 704
Ubuntu 9.04 Jaunty Jackalope
|
Re: Conky Weather Revisited V2
I am going to add an additional feature that will make less cpu intensive for multiday forecasts. But it may take some time, because school just started back up, and I am not use to my teaching schedule and my class schedule yet.
|
|
|
|
|
|
#5 | |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Sep 2007
Location: 34°35'S - 58°21'W
My beans are hidden!
|
Re: Conky Weather Revisited V2
Quote:
School? January? It's summ... OH! Up North, how soon we forget. I'm a patient man. Bruce Code:
Are we there yet?
__________________
|
|
|
|
|
|
|
#6 |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Jan 2007
Location: ~/PA/USA
Beans: 1,984
Ubuntu 8.04 Hardy Heron
|
Re: Conky Weather Revisited V2
Hey Bruce, where did you get your fonts? I only have the black and white. I like the color you have.
Did you redo those yourself? Been following this thread, seems to work good so far. I'm using the first script and still play'n around with it myself, doesn't seem to be buggie with my PC. Never mind Bruce, I just got it (FONTS) lol, you can change the color of the fonts. I was thinking image.....duh!
__________________
HP Pavilion DV9608nr Dual Boot | Compiz-Check | Partitioning | Compiz Plugins | bash_aliases | Installing nvidia drivers | using dd | gparted live cd | Google cheat sheet | Unix/Linux cheatsheet | intrepid 8.10 live cd | Uninstall Ubuntu Last edited by cdtech; January 15th, 2008 at 03:41 AM.. |
|
|
|
|
|
#7 |
|
Has an Ubuntu Drip
![]() Join Date: Jul 2006
Beans: 704
Ubuntu 9.04 Jaunty Jackalope
|
Re: Conky Weather Revisited V2
For some reason the first script had to be run through another script. This was because conky couldn't handle the functions in the bash script. I could have always taken them out, but it was harder to read, ugly, and harder to make changes. This version should be a bit faster than the old version. When I finish the new update one can use just two scripts for 5 days versus 10 scripts for 5 days. This, I hope will help with slower computers. But the formatting of one's weather section in conky will have to be very specific. Looks like even in conky sometimes you have to sacrifice beauty for performance.
|
|
|
|
|
|
#8 |
|
Has an Ubuntu Drip
![]() Join Date: Jul 2006
Beans: 704
Ubuntu 9.04 Jaunty Jackalope
|
Re: Conky Weather Revisited V2
Anyone want to beta test the new version? There are very specific setup criterion for this version. It requires specific font sizes and positioning. I may be able to mess with that a bit, so that the user can input those, but right now there is no way of adjusting besides trial and error in your .conkyrc Anyway, to test it make a new file weather_test.pl in ~/scripts. Now make it executable. If the output is not positioned correctly inside conky mess with the offset. If the temps don't line up correctly you will have to add or subtract spaces from the print on line 76 and most likely adjust the offset in conky.
Code:
chmod a+x ~/scripts/weather_test.pl PHP Code:
Code:
${voffset -5}${font weather:size=45}${alignc}${execi 3600 perl ~/scripts/weather_test.pl USVA0652 f 5dp}${font}$color
${font Candera:size=6}${offset 18}${execi 3600 perl ~/scripts/weather_test.pl USVA0652 f 5d}
Oh and I found a couple bugs in the original code. 1. If your connection is down when weather first tries to get the forecast it creates a blank file and tries to read from that file for the next hour until it can update it again, even if you restart conky. I will have to write a portion of the code that checks the size of the file. 2. The user can input 5dps and it will just output the 5d output. This is from the way I check cases. This may take some thinking and so it will take longer than problem 1. Last edited by lvleph; January 15th, 2008 at 10:47 AM.. |
|
|
|
|
|
#9 |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Jan 2007
Location: ~/PA/USA
Beans: 1,984
Ubuntu 8.04 Hardy Heron
|
Re: Conky Weather Revisited V2
I tried the test script but got tons of errors. I will check them out when I get a little more time though (work time). The weather.pl works good so far, the only issue I have is the character format for the degree symbol, I've tried everything to no avail. I would really like to have that.
__________________
HP Pavilion DV9608nr Dual Boot | Compiz-Check | Partitioning | Compiz Plugins | bash_aliases | Installing nvidia drivers | using dd | gparted live cd | Google cheat sheet | Unix/Linux cheatsheet | intrepid 8.10 live cd | Uninstall Ubuntu |
|
|
|
|
|
#10 | |||
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Sep 2007
Location: 34°35'S - 58°21'W
My beans are hidden!
|
Hi cdtech,
I have to do this. I know I don't have to, but I really do. It's the little devil in me. So what follows are the thoughts that went through my head as I read each statement. Quote:
DUH, use the colour command! Quote:
Quote:
------------------------ To continue in the present... Thanks for the chuckle. It did me good. Don't you just love it when something is staring you in the face and you can't see it because our mind tries to complicate things. NO! ![]() Bruce
__________________
|
|||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|