wakaget.pl (9)

1 Name: x2l2 2005-04-17 21:23 ID:BrNRfrn8

this is a perl scritp to get the wallpaper on the top of the /w board
sorry for my bad english :P
i use wakawall.jpg at default desktop on gnome
and make the system execute it every times i start the sesion

#!/usr/bin/perl
use LWP::Simple;

$url="http://www.cyril.dreamhost.com/w/wakaba.html";
$webpage = get($url);

if ($webpage =~ /.jpg/){
#take code between the first and second "<span clas..."
@trozo = split ('<span class="filesize">',$webpage,2);

#take all the code between 'href="' and 'jpg">' incusive
$begin = index( $trozo[1], 'href="');
$end = index ( $trozo[1], 'jpg">');
$ImageString = substr ($trozo[1], $begin, $end-$begin);

#whitout all html code
$ImageString =~ s/^href="//g;
$UriImage = 'http://www.cyril.dreamhost.com'.$ImageString.'jpg';

#image name without w/src/
$ImageName = substr ($ImageString,7 )."jpg";

#any knows a better way to do this?
#using only perl, no "system"
system("wget $UriImage");
system("cp $ImageName ~/wakawall.jpg");
system("mv $ImageName wakawall");
}
#end --------------------------------------

2 Name: #!usr/bin/anon 2005-04-20 11:45 ID:Heaven

2GET

3 Name: x2l2 2005-04-20 12:58 ID:BrNRfrn8

#any knows a better way to do this?
#using only perl, no "system"
system("wget $UriImage");
system("cp $ImageName ~/wakawall.jpg");
system("mv $ImageName wakawall");

4 Name: x2l2 2005-04-20 13:12 ID:BrNRfrn8

sorry for my bad english :P

5 Name: dmpk2k!hinhT6kz2E 2005-04-21 09:59 ID:CenHhJrY

Why not just repeat what you did to get the HTML? Probably something along these lines:

$data = get $UriImage;
open(FD, ">wakawall");
binmode FD;
print(FD, $data);
close FD;
copy ("wakawall", "~/wakawall.jpg");

Don't forget to include File::Copy, nor your die()s (nor strict mode...).

I've forgotten most of perl though, so I defer to anyone who actually knows how to beat it into submission.

6 Name: !WAHa.06x36 2005-04-21 12:21 ID:wTe20pnD

>>5 pretty much got it.

7 Name: dmpk2k!hinhT6kz2E 2005-04-22 02:20 ID:NoDXD0TZ

>>6
Is it possible to cheat a bit and do this?

print(FD, get $UriImage);

...instead of the original two lines?

8 Name: !WAHa.06x36 2005-04-22 13:03 ID:AbrhuaUf

Sure. Actually, I think you're supposed to write it as

print FD get $UriImage;

With no comma or parentheses. I am not sure if your version also works, though.

9 Name: Khisanth 2005-05-17 05:07 ID:mTd/x+M9

getstore( $UriImage, "$ENV{HOME}/wakawall/wakawall.jpg" );

This is assuming you already have a ~/wakawall directory.

This thread has been closed. You cannot post in this thread any longer.