1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
#! /usr/bin/perl
use strict;
use warnings;
# MODULES
use Tk; use Tk::Table;
use LWP::UserAgent;
# INITIALISATION
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" . $ua->agent); # ua de IE6
my $req = HTTP::Request->new(GET => "http://<a href="http://www.developpez.net/forums/");" target="_blank">www.developpez.net/forums/");</a>
$req->header('Accept' => 'text/html');
my $accueil = get_page() or die "Impossible de contacter developpez.net\n";
# liste des forums de developpez.net
my @forums = ($accueil =~ m|<span \s* class="forumlink"> \s* <a [^>]*> \s* ([^<]+) \s* </a> \s* <br \s* />|ixg);
# chaque entrée de ce tableau contient les informations suivantes :
# 0 nom du forum, 1 nombre de nouveaux messages, 2 nombres de nouveaux topics,
# 3 nombre de messages, 4 nombre de topics, 5 forum surveillé ou non, 6 son pour nouveau message ou non,
# 7 pop-up sur nouveau message ou non, 8 mail sur nouveau message ou non, 9 limite pour l'envoi d'un mail
my @main_info;
for (0..$#forums) {
$accueil =~ m|\Q$forums[$_]\E .+?
<td [^>]*> \s* <span [^>]*> \s* (\d+) \s* </span> \s* </td> \s*
<td [^>]*> \s* <span [^>]*> \s* (\d+) \s* </span> \s* </td> \s*
|ixms;
$main_info[$_] = [ $forums[$_], 0, 0, $2, $1, 0, 1, 1, 0, 1 ];
}
# intervalle en seconde entre deux mises à jour
my $intervalle = 120;
# MISE EN PLACE DE LA FENETRE
my $mw = MainWindow->new( -title => 'Surveillance des forums de Développez.net');
my $clock = $mw->repeat( $intervalle * 1000, \&maj );
my(@pl) = qw/-side top -expand yes -padx 10 -pady 10 -fill both/;
my $hight = $mw->Frame;
$hight->pack(qw/-side top -padx 10 -pady 5 -fill x/);
my $low = $mw->Frame;
$low->pack(@pl);
@pl = qw/-side left -padx 10 -expand yes -fill x/;
my $hleft = $hight->Frame;
$hleft->pack( @pl);
my $hright = $hight->Frame;
$hright->pack( @pl);
$hleft->Button( -text => 'Réinitialiser',
-command => \&reset_count )->pack( qw/-anchor w -side top -pady 1/ );
$hleft->Button( -text => 'Options',
-command => \&prefs )->pack( qw/-anchor w -side top -pady 1/ );
$hright->Button( -text => 'Quitter',
-command => [ $mw => 'destroy' ] )->pack( qw/-anchor e -side top -expand yes/ );
my $date = $low->Label( -text => 'Décompte depuis ' . localtime() );
$date->pack();
my $table_f = $low->Table(-rows => (scalar(@forums) + 1),
-columns => 4,
-scrollbars => 'e',
-fixedrows => 1,
-takefocus => 1);
$table_f->pack( -side => 'bottom' );;
$table_f->put( 0, 0, $table_f->Label( -text => " Surveillé ? ", -relief => 'raise' ));
$table_f->put( 0, 1, $table_f->Label( -text => "Forums", -relief => 'raise' ));
$table_f->put( 0, 2, $table_f->Label( -text => " Nouveaux messages ", -relief => 'raise' ));
$table_f->put( 0, 3, $table_f->Label( -text => " Nouveaux topics ", -relief => 'raise' ));
create_table();
$mw->maxsize( 1024, 600 );
MainLoop();
# CALLBACKS
sub create_table {
for (0..$#main_info) {
my $widget = $table_f->Checkbutton( -text => "",
-variable => \$main_info[$_][5],
-command => [\&change_surv_state => $_]);
$table_f->put( $_ + 1, 0, $widget );
$widget = $table_f->Label( -text => $main_info[$_][0] );
$table_f->put( $_ + 1, 1, $widget );
$widget = $table_f->Label( -text => $main_info[$_][1] );
$table_f->put( $_ + 1, 2, $widget );
$widget = $table_f->Label( -text => $main_info[$_][2] );
$table_f->put( $_ + 1, 3, $widget );
}
}
sub change_surv_state {
my $forum = shift;
if( not $main_info[$forum][5] ) {
$main_info[$forum][1] = 0;$main_info[$forum][2] = 0;
refresh( 1, $forum );
}
}
sub refresh {
my $only = shift;
if ( $only ) {
if( @_ ) {
my $widget = $table_f->get( $_[0] + 1, 2);
$widget->configure( -text => $main_info[$_][1] );
$widget = $table_f->get( $_[0] + 1, 3);
$widget->configure( -text => $main_info[$_][2] );
}
else {
for (0..$#main_info) {
if( $main_info[$_][5] ) {
my $widget = $table_f->get( $_ + 1, 2);
$widget->configure( -text => $main_info[$_][1] );
$widget = $table_f->get( $_ + 1, 3);
$widget->configure( -text => $main_info[$_][2] );
}
}
}
}
else {
for (0..$#main_info) {
my $widget = $table_f->get( $_ + 1, 2);
$widget->configure( -text => $main_info[$_][1] );
$widget = $table_f->get( $_ + 1, 3);
$widget->configure( -text => $main_info[$_][2] );
}
}
}
sub reset_count {
$date->configure( -text => 'Décompte depuis ' . localtime() );
for (0..$#main_info) {
$main_info[$_][1] = 0;$main_info[$_][2] = 0;
}
refresh( 0 );
}
sub get_page {
my $res = $ua->request($req);
if ($res->is_success) {
return $res->content;
}
else {
print "Error: " . $res->status_line . "\n";
return undef;
}
}
sub maj {
$accueil = get_page() or return;
for (0..$#main_info) {
if( $main_info[$_][5] ) {
my $forum = $main_info[$_][0];
if( $accueil =~ m|\Q$forum\E .+?
<td [^>]*> \s* <span [^>]*> \s* (\d+) \s* </span> \s* </td> \s*
<td [^>]*> \s* <span [^>]*> \s* (\d+) \s* </span> \s* </td> \s*
|ixms ) {
if( $2 > $main_info[$_][3] ) {
print "\a\a" if ($main_info[$_][6]);
popup( $_ ) if $main_info[$_][7] ;
mail( $_ ) if $main_info[$_][8] and $main_info[$_][1] > $main_info[$_][9];
}
$main_info[$_][1] += ($2 - $main_info[$_][3]);$main_info[$_][2] += ($1 - $main_info[$_][4]);
$main_info[$_][3] = $2;$main_info[$_][4] = $1;
}
}
}
refresh( 1 );
}
sub popup {
$mw->messageBox( -default => 'Ok',
-message => 'Nouveau message sur le forum '.$main_info[$_[0]][0],
-title => 'Nouveau message',
-icon => 'info',
-type => 'Ok')
} |
Partager