check html file size

X

Xah Lee

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
(e-mail address 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::Dumper;
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__
 
M

Matt Garrish

Xah Lee said:
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
 
G

Grant Edwards

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

Sure. It'll cost you $110/hour with a 2-hour minimum. Where do
I send the invoice?
 
E

Erik Max Francis

Matt said:
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.
 
R

Richard Gration

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

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

Ulrich Hobelmann

Richard said:
Are you fucking seriously fucking expecting some fucking moron to
translate your tech geeking fucking code moronicity? Fucking try writing
it fucking properly in fucking Perl first.

Fucking excuse me?

Fucking maybe you should fucking go fucking **** your fucking self...

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

Sherm Pendley

Richard Gration said:
Are you fucking seriously fucking expecting some fucking moron to
translate your tech geeking fucking code moronicity? Fucking try writing
it fucking properly in fucking Perl first.

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

Lenny Bruce would be so fucking proud.

sherm--
 
S

Sherm Pendley

Ulrich Hobelmann said:
Fucking excuse me?

Fucking maybe you should fucking go fucking **** your fucking 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--
 
R

Ray Dillinger

Richard said:
... fucking ... fucking ... fucking ... fucking ... Fucking ... fucking
> ... fucking

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
 
U

Ulrich Hobelmann

Sherm said:
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.
 
R

Richard Gration

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

Thanks, Sherm. I knew someone would get it. I think Bear and Ulrich
haven't yet been exposed to Xah "in full effect" ;-) They're probably
denizens of the Scheme group which seems to be a new entry on Xah's "this
newsgroup needs spamming" list ;-)
Lenny Bruce would be so fucking proud.

LOL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top