Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

repviewer

by epoptai (Curate)
on Feb 04, 2001 at 18:45 UTC ( #56309=sourcecode: print w/ replies, xml ) Need Help??

Category: PerlMonks.org Related Scripts
Author/Contact Info epoptai
Description: repviewer parses the reputation file generated by jcwren's luke_repwalker.pl to generate a full list of your articles sorted by creation time, title or reputation just like perlmonks user search except that all articles are displayed on one page. Just set $pm and $rep.
#!perl
# repviewer parses the reputation file generated by jcwren's luke_repw
+alker.pl 
# to generate a full list of your articles sorted by creation time, ti
+tle or 
# reputation just like the one at perlmonks user search except that al
+l 
# articles are displayed on one page. Just set $pm and $rep below.

use strict;
use CGI qw(:standard *table);
use HTML::Entities;

my$pm  = 'http://perlmonks.org'; # your login domain for perlmonks, us
+ed for node link
my$rep = 'c:\.rep.epoptai'; # full path to rep file generated by luke_
+repwalker.pl

my%i = map{$_ => param($_)} param;
my($mode,$td,$ta,$rd,$ra,$ca,$cd);

if($i{'o'} eq 'title DESC'){$mode='td'; $td='selected'}
if($i{'o'} eq 'title ASC'){$mode='ta'; $ta='selected'}
if($i{'o'} eq 'reputation DESC'){$mode='rd'; $rd='selected'}
if($i{'o'} eq 'reputation ASC'){$mode='ra'; $ra='selected'}
if($i{'o'} eq 'createtime ASC'){$mode='ca'; $ca='selected'}
if(($i{'o'} eq 'createtime DESC') or (!$i{'o'})){$mode='cd'; $cd='sele
+cted'}

print header,start_html(-title=>'repviewer',-bgcolor=>'#a0a0a0');
print<<HTML; # perlmonks sort form
<style><!-- td{ font-family: arial ; font-size: 80% ;} // --></style>
<FORM>
Order By:
<SELECT NAME="o">
<OPTION $td VALUE="title DESC">By Title Reverse
<OPTION $ta VALUE="title ASC">By Title
<OPTION $ra VALUE="reputation ASC">Lowest Reputation First
<OPTION $rd VALUE="reputation DESC">Highest Reputation First
<OPTION $ca VALUE="createtime ASC">Oldest First
<OPTION $cd VALUE="createtime DESC">Newest First</SELECT>
<INPUT TYPE="submit" VALUE="sort"></FORM>
<blockquote><pre>
HTML

open(REP,"< $rep") or die "$!";
my@rep=<REP>;
die "$!" unless close(REP);

my(%reps,%tits,%dates,@reps,@tits,$tot);
for(@rep){
    $_=~m/^"(\d+)","(.*)","(-?\d+)","(.*)"$/;
    my$node = $1;
    my$title= $2;
    my$rep  = $3;
    my$date = $4;
    &encode_entities($title);
    $reps{$node}=$rep;
    $tits{$node}=$title;
    $dates{$node}=$date;
    }
for(values(%reps)){
    $tot += $_
    }
for(keys(%tits)){
    push @tits, $tits{$_}.'=|||='.$_
    }
my$i=1;
printf ("    Total articles: %d\n", scalar @rep); # nod to luke
printf ("  Total reputation: %d\n", $tot);
printf ("Average reputation: %3.2f\n", $tot / scalar @rep);   
print '</pre></blockquote>';

if($mode=~/td|ta/){ # by title
    print start_table({-border=>'1',-cellpadding=>'2',-cellspacing=>'1
+',-bgcolor=>'#c0c0c0'});
    print '<tr bgcolor="#ffffff"><td>num<td><b>title<td>rep<td>date</t
+r>';
    
    if($mode=~/ta/){ # ascending
        for(sort{ lc($a) cmp lc($b)}(@tits)){
            my($f,$b)=split(/=\|\|\|=/,$_);
            print<<HTML;
            <tr>
            <td>$i</td>
            <td><a href="$pm/index.pl?node_id=$b">$f</a></td>
            <td align="right">$reps{$b}</td>
            <td>$dates{$b}</td></tr>
HTML
            $i++
            }
        }
        
    if($mode=~/td/){ # descending
    for(reverse(sort{ lc($a) cmp lc($b)}(@tits))){
        my($f,$b)=split(/=\|\|\|=/,$_);
        print<<HTML;
        <tr>
        <td>$i</td>
        <td><a href="$pm/index.pl?node_id=$b">$f</a></td>
        <td align="right">$reps{$b}</td>
        <td>$dates{$b}</td></tr>
HTML
        $i++
        }
    }
print end_table,end_html;
exit
}

if($mode=~/cd|ca/){ # by date
    print start_table({-border=>'1',-cellpadding=>'3',-cellspacing=>'1
+',-bgcolor=>'#c0c0c0'});
    print '<tr bgcolor="#ffffff"><td>num<td>title<td>rep<td><b>date</t
+r>';
    }

if($mode eq 'cd'){@rep=reverse(@rep)} # descending
my$i=1;
for(@rep){
    $_=~m/^"(\d+)","(.*)","(-?\d+)","(.*)"$/;
    my$node = $1;
    my$title= $2;
    my$rep  = $3;
    my$date = $4;
    &encode_entities($title);
    $reps{$node}=$rep;
    $tits{$node}=$title;
    $dates{$node}=$date;
    if($mode=~/cd|ca/){
        print<<HTML;
        <tr>
        <td>$i</td>
        <td><a href="$pm/index.pl?node_id=$node">$title</a></td>
        <td align="right">$rep</td>
        <td>$date</td></tr>
HTML
        }
    $i++
    }
if($mode=~/cd|ca/){
    print end_table,end_html;
    exit
    }

if($mode=~/rd|ra/){ # by rep
    print start_table({-border=>'1',-cellpadding=>'3',-cellspacing=>'1
+',-bgcolor=>'#c0c0c0'});
    for(keys(%reps)){
        push @reps, $reps{$_}.'='.$_ # construct a sortable rep array
        }
    for(@reps){
        my($a,$b)=split(/=/,$_);
        if($a < 10){
            $_=~s/(\d)/0$1/o # pad for sort
            }
        }
    $i=1;
    print '<tr bgcolor="#ffffff"><td>num<td>title<td><b>rep<td>date</t
+r>';
    if($mode=~/rd/){
        for(reverse(sort{$a cmp $b}(@reps))){ # descending
            my($f,$b)=split(/=/,$_);
            if($f=~/^0\d$/){$f=~s/^0//o} # strip sort padding
            if($f=~/^-0\d$/){$f=~s/^-0/-/o}
            print<<HTML;
            <tr>
            <td>$i</td>
            <td><a href="$pm/index.pl?node_id=$b">$tits{$b}</a></td>
            <td align="right">$f</td>
            <td>$dates{$b}</td></tr>
HTML
            $i++
            }
        }
    if($mode=~/ra/){ # ascending
        for(sort{$a cmp $b}(@reps)){
            my($f,$b)=split(/=/,$_);
            if($f=~/^0\d$/){$f=~s/^0//o}
            if($f=~/^-0\d$/){$f=~s/^-0/-/o}
            print<<HTML;
            <tr>
            <td>$i</td>
            <td><a href="$pm/index.pl?node_id=$b">$tits{$b}</a></td>
            <td align="right">$f</td>
            <td>$dates{$b}</td></tr>
HTML
            $i++
            }
        }
    print end_table,end_html;
    }
exit

Comment on repviewer
Download Code
(jcwren) Re: repviewer
by jcwren (Prior) on Feb 05, 2001 at 00:49 UTC

    Excellent!

    --Chris

    e-mail jcwren

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://56309]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-27 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls