Okay, this is silly, I know - but sometimes I just cannot resist the temptation. Here is an example of useful webscraping: If you meta moderate on slashdot, you get more moderation points.
Okay so maybe it is not very useful. Actually, I don't even use my moderation points. ever.
--
01Okt2004 PS.
Save the script and give it your username and password.
Usage:
tclsh slashmetamod.tcl ?username ?password??
It will prompt you if you do not provide them on the commandline.
# Slashdot meta moderator.
# This script will do your meta moderations for you.
package require http
# First, log in to slashdot:
set username [lindex $argv 0]
set password [lindex $argv 1]
if { $username eq "" } {
puts -nonewline "Username: "
flush stdout
set username [gets stdin]
}
if { $password eq "" } {
puts -nonewline "Password: "
flush stdout
set password [gets stdin]
}
set p 0.8 ;# p=0.8 - 80% of moderations considered 'fair'.
puts "Logging into slashdot as $username..."
http::config -useragent "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)"
set q [http::formatQuery unickname $username returnto http://slashdot.org \
op userlogin upasswd $password login_temp yes]
set tok [http::geturl http://slashdot.org/login.pl -query $q]
upvar \#0 $tok state
set cookies [list]
foreach {name value} $state(meta) {
if { $name eq "Set-Cookie" } {
lappend cookies [lindex [split $value {;}] 0]
}
}
http::cleanup $tok
puts "Getting posting numbers to metamoderate..."
set tok2 [::http::geturl http://slashdot.org/metamod.pl -headers [list Cookie [join $cookies {;}]]]
if { [regexp {You are currently not eligible to Meta Moderate} [http::data $tok2]] } {
puts "You are currently not eligible to Meta Moderate."
exit
}
set items [regexp -all -inline {<INPUT TYPE="RADIO" NAME="(mm[0-9]*)" VALUE="-">} [http::data $tok2]]
http::cleanup $tok2
set q ""
foreach {x mm} $items {
set fair [expr {rand() <= $p}]
if { $fair } {
set choice +
} else {
set choice -
}
lappend q [http::formatQuery $mm $choice]
puts "Posting $mm: $choice"
}
lappend q [http::formatQuery op MetaModerate]
set q [join $q "&"]
set tok3 [::http::geturl http://slashdot.org/metamod.pl -query $q -headers [list Cookie [join $cookies {;}]]]
if { [regexp {You are currently not eligible to Meta Moderate} [http::data $tok2]] } {
puts "MetaModeration failed, slashdot said:"
puts "You are currently not eligible to Meta Moderate."
exit
}
puts "MetaModerated."