Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > check html file size

Reply
Thread Tools

check html file size

 
 
Xah Lee
Guest
Posts: n/a
 
      10-05-2005
would anyone like to translate the following perl script to Python or
Scheme (scsh)?

the file takes a inpath, and report all html files in it above certain
size. (counting inline images)
also print a sorted report of html files and their size.

(a copy of the script is here:
http://xahlee.org/_scripts/check_file_size.pl
)

Xah
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://xahlee.org/


# perl

# Tue Oct 4 14:36:48 PDT 2005
# given a dir, report all html file's size. (counting inline images)
# XahLee.org

use Data:umper;
use File::Find;
use File::Basename;

$inpath = '/Users/t/web/mydirectory/';
$sizeLimit = 800 * 1000;

# $inpath = $ARGV[0]; # should give a full path; else the
$File::Find::dir won't give full path.
while ($inpath =~ m@^(.+)/$@) { $inpath = $1;} # get rid of trailing
slash

die "dir $inpath doesn't exist! $!" unless -e $inpath;


##################################################
# subroutines


# getInlineImg($file_full_path) returns a array that is a list of
inline images. For example, it may return ('xx.jpg','../image.png')
sub getInlineImg ($) { $full_file_name= $_[0];
@linx =(); open (FF, "<$full_file_name") or die "error: can not open
$full_file_name $!";
while (<FF>) { @txt_segs = split(m/img/, $_); shift @txt_segs;
for $lin (@txt_segs) { if ($lin =~ m@ src\s*=\s*\"([^\"]+)\"@i) {
push @linx, $1; }}
} close FF;
return @linx;
}

# linkFullPath($dir,$locallink) returns a string that is the full path
to the local link. For example,
linkFullPath('/Users/t/public_html/a/b', '../image/t.png') returns
'Users/t/public_html/a/image/t.png'. The returned result will not
contain double slash or '../' string.
sub linkFullPath($$){ $result=$_[0] . $_[1]; while ($result =~
s@\/\/@\/@) {}; while ($result =~ s@/[^\/]+\/\.\.@@) {}; return
$result;}


# listLocalLinks($html_file_full_path) returns a array where each
element is a full path of local links in the html.
sub listLocalLinks($) {
my $htmlfile= $_[0];

my ($name, $dir, $suffix) = fileparse($htmlfile, ('\.html') );
my @aa = getlinks($htmlfile);
@aa = grep(!m/\#/, @aa);
@aa = grep (!m/^mailto:/, @aa);
@aa = grep (!m/^http:/, @aa);

my @linkedFiles=();
foreach my $lix (@aa) { push @linkedFiles, linkFullPath($dir,$lix);}
return @linkedFiles;
}


# listInlineImg($html_file_full_path) returns a array where each
element is a full path to inline images in the html.
sub listInlineImg($) {
my $htmlfile= $_[0];

my ($name, $dir, $suffix) = fileparse($htmlfile, ('\.html') );
my @aa = getInlineImg($htmlfile);

my @result=();
foreach my $ele (@aa) { push @result, linkFullPath($dir,$ele);}
return @result;
}

##################################################
sub checkLink {
if (
-T $File::Find::name
&& $File::Find::name =~ m@\.html$@
) {
$total= -s $File::Find::name;
@h2 = listInlineImg($File::Find::name);
for my $ln (@h2) {$total += -s $ln;};
if ( $total > $sizeLimit) {print "problem: file:
$File::Find::name, size: $total\n";}

push (@result, [$total, $File::Find::name]);
};
}

find(\&checkLink, $inpath);

@result = sort { $b->[0] <=> $a->[0]} @result;

print Dumper(\@result);
print "done reporting. (any file above size are printed above.)";

__END__

 
Reply With Quote
 
 
 
 
Matt Garrish
Guest
Posts: n/a
 
      10-05-2005

"Xah Lee" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> would anyone like to translate the following perl script to Python or
> Scheme (scsh)?


Even if you weren't an incredibly offensive and petulant poster, what makes
you think anyone would write a script from you?

Matt


 
Reply With Quote
 
 
 
 
Erik Max Francis
Guest
Posts: n/a
 
      10-05-2005
Matt Garrish wrote:

> Even if you weren't an incredibly offensive and petulant poster, what makes
> you think anyone would write a script from you?


Because in addition to being offensive and petulant, he's also an idiot.

--
Erik Max Francis && (E-Mail Removed) && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
There is no fate that cannot be surmounted by scorn.
-- Albert Camus
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      10-05-2005
Xah Lee <(E-Mail Removed)> wrote:

> would anyone like to translate the following perl script to Python or
> Scheme (scsh)?



Yes, I would.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Richard Gration
Guest
Posts: n/a
 
      10-05-2005
On Tue, 04 Oct 2005 17:44:02 -0700, Xah Lee wrote:

> would anyone like to translate the following perl script to Python or
> Scheme (scsh)?


Are you ****ing seriously ****ing expecting some ****ing moron to
translate your tech geeking ****ing code moronicity? ****ing try writing
it ****ing properly in ****ing Perl first.

--
I guess everybody's the same: Gotta be good at your job before you can enjoy the rest of your life
-- Cole Trickle

 
Reply With Quote
 
Ulrich Hobelmann
Guest
Posts: n/a
 
      10-05-2005
Richard Gration wrote:
> Are you ****ing seriously ****ing expecting some ****ing moron to
> translate your tech geeking ****ing code moronicity? ****ing try writing
> it ****ing properly in ****ing Perl first.


****ing excuse me?

****ing maybe you should ****ing go ****ing **** your ****ing self...

Seriously, Xah might be a troll, but this is just pathetic.

--
We're glad that graduates already know Java,
so we only have to teach them how to program.
somewhere in a German company
(credit to M. Felleisen and M. Sperber)
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      10-06-2005
Richard Gration <(E-Mail Removed)> writes:

> Are you ****ing seriously ****ing expecting some ****ing moron to
> translate your tech geeking ****ing code moronicity? ****ing try writing
> it ****ing properly in ****ing Perl first.


Good ****ing job! That's the funniest ****ing response I've ever ****ing seen
to Xah's ****ing moronistic ****ing nonsense.

Lenny Bruce would be so ****ing proud.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      10-06-2005
Ulrich Hobelmann <(E-Mail Removed)> writes:

> Richard Gration wrote:
>> Are you ****ing seriously ****ing expecting some ****ing moron to
>> translate your tech geeking ****ing code moronicity? ****ing try writing
>> it ****ing properly in ****ing Perl first.

>
> ****ing excuse me?
>
> ****ing maybe you should ****ing go ****ing **** your ****ing self...
>
> Seriously, Xah might be a troll, but this is just pathetic.


I'm guessing you didn't get the joke then. I think Richard's response was a
parody of Xah's "style" - a funny parody, at that.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
Ray Dillinger
Guest
Posts: n/a
 
      10-06-2005
Richard Gration wrote:

> ... ****ing ... ****ing ... ****ing ... ****ing ... ****ing ... ****ing
> ... ****ing


My friend, you can learn to use a far richer vocabulary of
obscenities. If your creative flow is blocked by the fear
that you can't spell more dirty words correctly, you can
dispel this fear with a few evenings of study and preparation.

Amaze your friends! Amuse your enemies! Enrich your
vocabulary! You can learn the joys of cussing seven
times in the same sentence without resorting to repetition!
For extra points, and with suitable study, you can even
learn to write entire paragraphs of _original_ obscenity!

Just imagine how much clearer your point would have been if
you'd called him a jizz-licking dogcock grabber! Why insult
his code with a vague word like "moronicity" when you could
use "steaming pile of entrails" or better yet, "bucket of
fermented ballsweat?" wouldn't that have made your technical
point much clearer?

Now go, and don't attempt obscenity in public again until
you learn how.

Bear


 
Reply With Quote
 
Ulrich Hobelmann
Guest
Posts: n/a
 
      10-06-2005
Sherm Pendley wrote:
> I'm guessing you didn't get the joke then. I think Richard's response was a
> parody of Xah's "style" - a funny parody, at that.


If you take all the line noise in Perl as swearing
I suppose I'm lucky I can't read it.

--
We're glad that graduates already know Java,
so we only have to teach them how to program.
somewhere in a German company
(credit to M. Felleisen and M. Sperber)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Preferred Size, Minimum Size, Size Jason Cavett Java 5 05-25-2008 08:32 AM
mega pixels, file size, image size, and print size - Adobe Evangelists Frank ess Digital Photography 0 11-14-2006 05:08 PM
check uploaded file's file size? h3m4n Python 2 07-08-2006 08:56 PM
check html file size Xah Lee Python 11 10-06-2005 01:54 PM
Upload file Check file size lawrence ASP .Net 4 06-10-2004 08:02 PM



Advertisments