Jump to content

Translating perl script into bash script


Recommended Posts

Can somone translate this perl script

 

#!/usr/bin/perl

use strict;
use warnings;

our $url = 'http://www.foksuk.nl';
our $prefix = 'http://www.foksuk.nl/';
our $attr_value = '0';
our $attr_name = 'border';
our $regex = 'd\d+\.(gif|jpg)$';

$0=~m|^(.*/).*?$|;
require $1.'komics.pm';

 

into a bash script. As far as I can see the script works fine. I get the correct URL but when I run it from komics (it should fetch a comic) instead of an gif file I get an php file. I had the same (sort of) problem with an earlier perl script from Papaschtroumpf (http://mandrakeusers.org/index.php?showtopic=21696) but the bash script from Aru works very well.

Link to comment
Share on other sites

Here you are (as bonus I put some code to retrieve and show you the comic strip w/o Komics ;)

 

btw it is better to use not such restrictive regexps for such easy tasks. Also your regexp: d\d+\.(gif|jpg)$ ends with a dollar sign that matches end of line when the image in that web page is not on an end of line (I may be wrong because I have a very limited knowledge of perl regexps.

 

here is the script

 

#! /bin/bash

regexp='.*\(imggif.php?i=/upload/d[0-9]\{1,4\}.gif\).*'

main_url="http://www.foksuk.nl/"

img_url=$(wget -qO - $main_url | sed -n "s@$regexp@$main_url\1@p")

echo -n "${img_url}" # outputs todays image name

 

# BONUS! ----------------------------------------

# this part allows you to see the strip right now,

# remove if you just want the img url:

imgname=Cartoon_van_de_dag.gif

echo

wget -qO $imgname "$img_url"

eog $imgname

 

HTH

Link to comment
Share on other sites

Thanks for your help. The script works fine, only just as fine as the perl script. :( Komics is naming the file komics1aFwAeb.php (the bit before php changes of course). Kuickshow won't show php files and kview only when it's not the 'designated' apllication to open the file. But I can let komics save it and than it just opens fine in kview.

 

http://www.foksuk.nl/imggif.php?i=/upload/d686.gif Is the complete url. I'm guessing komics cuts of (after the download) at imggig.php. I've no idea what files are involved so we'll have to wait for the next bug fix. :)

 

Thanks again for your help

Link to comment
Share on other sites

I've no idea what files are involved so we'll have to wait for the next bug fix. :)

mean while you can hack a little bit my script and lie komics telling it that the url is the downloaded comic strip ;) for example:

#! /bin/bash

regexp='.*\(imggif.php?i=/upload/d[0-9]\{1,4\}.gif\).*'

main_url="http://www.foksuk.nl/"

img_url=$(wget -qO - $main_url | sed -n "s@$regexp@$main_url\1@p")

imgname=~/Cartoon_van_de_dag.gif

wget -qO $imgname "$img_url"

echo -n "$imgname" # outputs the path to the comic image, that will be enough for comics

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...