Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

The DU Hidebot

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » The DU Lounge Donate to DU
 
Ellen Forradalom Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Oct-20-05 12:29 AM
Original message
The DU Hidebot
#!/usr/bin/perl -w

#
# The DU Hidebot
# A Perl script to mass hide threads in a forum 
# based on a word or phrase
# Name: du_hidebot.pl
# Author: Ellen Forradalom
#
# Usage:
# % du_hidebot.pl --forum=[lbn|ed|gd|gdp|lounge] \
#   --hide=[string] \
#   --username=[name] --password=[pwd] \
#   [--pages=n]
#
# forum: one of LBN, Editorials, GD, GDP, Lounge
# hide: hide all threads with this word or phrase
# username, password: for logging in
# pages: only look n pages deep.
#
# Note: Enclose all phrases or usernames with spaces in
quotes:
#  --username="My Username" or --hide="Dick
Cheney"\n';
#
# Example: 
# % du_hidebot.pl --forum=gd --hide=Schiavo
--username="Ellen Forradalom" --password="In
Your Dreams, Nosey Parker"
# This hid 160+ threads during Schiavopalooza.


    
use strict;
use WWW::Mechanize;
use Getopt::Long;
use CGI qw(:standard);

my $baseurl =
"http://www.democraticunderground.com/discuss";
my $boardurl = "$baseurl/duboard.php?";

# Forum abbreviations

my %abbrevs = (
 "Latest Breaking News" => "lbn",
 "Editorials and Other Articles" =>
"ed",
 "General Discussion" => "gd",
 "General Discussion: Politics" =>
"gdp",
 "The DU Lounge" => "lounge",
);


my %forums = ();


my $mech = WWW::Mechanize->new( autocheck => 1 );

my $forum  = undef;
my $hide = undef;
my $pages = undef;
my $username  = undef;
my $password = undef;


GetOptions(
"forum=s" => \$forum,
"hide=s"  => \$hide,
"pages=s"  => \$pages,
"username=s" => \$username,
"password=s"  => \$password,

) or exit 1;

usage() unless ($forum && $hide && $username
&& $password);
$pages ||= 20;

# Log in to DU
    $mech->get($boardurl . "az=login");
    $mech->submit_form(
        form_name => "thisform",
        fields      => { username => $username, password
=> $password },
    );
    die unless ($mech->success);


# Go to DU Forums lobby
$mech->get( $boardurl . "az=show_forums" );

# Get the current forum names and numbers

my @links = $mech->find_all_links(
               tag => "a", 
               url_regex =>
qr/az=show_topics&forum=\d+/i 
            );

foreach my $l (@links) {
	my $url  = $l->url();
	my $text = $l->text();

    my $q = new CGI($url);
	
	next if $text eq "";

	if ($abbrevs{$text}) {
		$forums{$abbrevs{$text}} = $q->param("forum"); 

	}
}

my @hide_forums = split /,/, $forum;
my @hidden; 

# Now get the forum listings and start hiding.
foreach my $h (@hide_forums) {
	foreach my $page (1..$pages) {

		my $url = $boardurl .
"az=show_topics&forum=$forums{$h}&page=$page";
  		warn "$h: page $page\n";
  
  
		$mech->get($url);
  
		my @threadlinks = $mech->find_all_links(
							tag => "a", 
							text_regex => qr/$hide/i 
							);							
            
		foreach my $tl (@threadlinks) {
			my $url  = $tl->url_abs();
			my $text = $tl->text();

			my $qs = (split /\?/, $url)[1];
			my $q = new CGI($qs);
	        my $az = $q->param('az');
	        
	        my ($forum, $thread);
	        if ($az eq "show_mesg") {
				$forum = $q->param("forum");
				$thread = $q->param("topic_id");
			} elsif ($az eq "view_all") {	
				($forum, $thread) = $q->param("address") =~
/^(\d+)x(\d+)$/;
			} else {
				warn "$az: don't know what this is;"
			}
	
			my $hl = $mech->find_link(
					   url_regex =>
qr/az=hide_thread&forum=$forum&thread=$thread/i 
					 );
                        
            my $hideurl = $baseurl . "/" .
$hl->url();
			$mech->get( $baseurl . "/" . $hl->url() );
		
			if ( $mech->content() =~ /You have hidden the thread/) {
				push @hidden, "$h: ". $tl->text();
			}
			$mech->back();
		}	
	}
}

print "Hid ", scalar @hidden, "
threads:\n";
map { print "$_\n"; } @hidden;



sub usage {
	
	print "Usage:\n";
	print "$0 --forum=[lbn|ed|gd|gdp|lounge] --hide=[string]
--username=[name] --password=[pwd] [--pages=n]\nwhere\n";
	
	print "--forum: one of LBN, Editorials (ED), GD, GDP or
the Lounge\n";
	print "--hide: hide all threads containing this word or
phrase\n";
	print "--username, --password: for logging in\n";
	print "--pages=n: only look n pages deep, starting from
top.  Optional; default is 20 pages deep\n\n";
	print 'Enclose all phrases or usernames with spaces in
quotes: --username="My Username" or
--hide="Dick Cheney"\n';
	
	exit 1;


}
Printer Friendly | Permalink |  | Top

Home » Discuss » The DU Lounge Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC