Please Scroll Down to See Forums Below
napsgear
genezapharmateuticals
domestic-supply
puritysourcelabs
UGL OZ
UGFREAK
napsgeargenezapharmateuticals domestic-supplypuritysourcelabsUGL OZUGFREAK

The end of the electric sheep - (pseudo)full disclosure

use Data::Dumper;
use Storable;

#scan in the dict file and dump to an array - later chop up the array.
$wordlist = 'pos.txt';

##############
#reads in wordlist and returns an array of the words
sub scanWordlist{
open(DAT, $wordlist) || die("Could not open file!");
my @rawData=<DAT>;
close(DAT);
return @rawData;
}
##############

##############
#helper function - clean out the stuff from the array that won't be used
sub cleanArray{
my $i;
for($i=0;$i<$#wordlist+1;$i++){
my $tempString = $wordlist[$i];
#remove the newline.
chomp($tempString);
#occasionally will have multiple chars at the end, if there are multiples, just kill it
#will lose some that way, but will have to do for now.
#so split the word into an array
my @tempArr = split(//,$tempString);
#the end of the array
my $a = $#tempArr;
$tempChar = $tempArr[$a];
if($tempChar ne ' '){
if($tempArr[$a-1] ne ' '){
#has two chars at the end, remove from the array
splice(@wordlist,$i,1);
}
if($tempChar eq '!' || $tempChar eq 'p' || $tempChar eq 'D' || $tempChar eq 'I' || $tempChar eq 'o'){
#remove it from the array and add it to the hash.
splice(@wordlist,$i,1);
}
if($tempChar eq 'P' || $tempChar eq 'h' || $tempChar eq 't' || $tempChar eq 'i' || $tempChar eq 'C'){
#remove it from the array and add it to the hash.
splice(@wordlist,$i,1);
}
}
}

}
##############


##############
#make a hash of verbs
#read from the global wordlist array
#--does some work in it that will clear out some of the junk from the wordlist arr, so it will get faster as these go and it is shortened
#
#removes over 60K entries from the main array - so the next ones should be faster - this one isn't so fast.
sub createVerbHash{
my %verbHash;
my $i;
for($i=0;$i<$#wordlist+1;$i++){
my $tempString = $wordlist[$i];
#remove the newline.
chomp($tempString);
#occasionally will have multiple chars at the end, if there are multiples, just kill it
#will lose some that way, but will have to do for now.
#so split the word into an array
my @tempArr = split(//,$tempString);
#the end of the array
my $a = $#tempArr;
$tempChar = $tempArr[$a];
if($tempChar eq 'V'){
#remove it from the array and add it to the hash.
splice(@wordlist,$i,1);
#get rid of the last char
chop($tempString);
#remove the whitespace
$tempString=~s/^\s+//g;
$tempString=~s/\s+$//g;
#add the string to the hash.
$verbHash{$tempString}++;
}
}
return %verbHash;
}
##############

##############
#make a hash of nouns
#removes another nearly 78K from the array
sub createNounHash{
my %nounHash;
my $i;
for($i=0;$i<$#wordlist+1;$i++){
my $tempString = $wordlist[$i];
#remove the newline.
chomp($tempString);
#occasionally will have multiple chars at the end, if there are multiples, just kill it
#will lose some that way, but will have to do for now.
#so split the word into an array
my @tempArr = split(//,$tempString);
#the end of the array
my $a = $#tempArr;
$tempChar = $tempArr[$a];
if($tempChar eq 'N'){
#remove it from the array and add it to the hash.
splice(@wordlist,$i,1);
#get rid of the last char
chop($tempString);
#remove the whitespace
$tempString=~s/^\s+//g;
$tempString=~s/\s+$//g;
#add the string to the hash.
$nounHash{$tempString}++;
}
}
return %nounHash;
}
##############


##############
#make one of adjectives
#that first word is a variable one as well.
sub createAdjHash{
my %adjHash;
my $i;
for($i=0;$i<$#wordlist+1;$i++){
my $tempString = $wordlist[$i];
#remove the newline.
chomp($tempString);
#occasionally will have multiple chars at the end, if there are multiples, just kill it
#will lose some that way, but will have to do for now.
#so split the word into an array
my @tempArr = split(//,$tempString);
#the end of the array
my $a = $#tempArr;
$tempChar = $tempArr[$a];
if($tempChar eq 'A'){
#remove it from the array and add it to the hash.
splice(@wordlist,$i,1);
#get rid of the last char
chop($tempString);
#remove the whitespace
$tempString=~s/^\s+//g;
$tempString=~s/\s+$//g;
#add the string to the hash.
$adjHash{$tempString}++;
}
}
return %adjHash;
}
##############


## MAIN ##
#read in stuff from dict file into an array.
@wordlist = scanWordlist();
cleanArray();#pretty sure this newer function makes a few of the lines in the following functions obsolete - but no biggie.
%verbHash = createVerbHash();
store(\%verbHash , 'verbHash.txt');
%nounHash = createNounHash();
store(\%nounHash , 'nounHash.txt');
%adjHash = createAdjHash();
store(\%adjHash , 'adjHash.txt');

#---------------------------------------------------------

#use strict;#disable this during debugging, then once in cron enable
use Storable;#excellent way to store complex objects like hashes
use LWP::Simple;#how we talk to the server
use Data::Dumper;#this is technically only for debugging - good for seeing if a hash is correctly formatted
use HTML::Parser;#how to edit the HTML out of posts
use HTTP::Request::Common qw(POST);#more talking to the server
use LWP::UserAgent;#more talking to the server
use HTTP::Cookies;#more talking to the server
use URI::URL;#more talking to the server

#these are files that get created once from a large dict file and are pulled into a hash on runtime
$adjFile = 'adjHash.txt';
$nounFile = 'nounHash.txt';
$verbFile = 'verbHash.txt';

$timeAtWriting = '1015904367';#seconds since 1970 at the time of the script being written
#60 seconds in a minute, 60 mins in an hour, 24 hours in a day... 86400 secs in a day.
#for every day, that the new time has on top of the old time, add 30 posts to the max post ID
$minPostID = '120700';
$maxPostID = '121137';#this is the max post for the day this was written, based on time can add logically more on there to find newer ones

$chatpage = 'http://boards.elitefitness.com/forum/showthread.php?s=&threadid=';#needs the threadID added on before using - "s" value was stripped out

##########
#takes in a string that points to a file and returns the associated hash in that file
sub loadHashFromFile{
my ($tempString) = @_;
my %hash = %{ retrieve($tempString) };
return %hash;
}
##########

################################
#a function to go and grab all the text (including tags)
#on a web page that is passed to it and return it as a string
sub grabPage{
my($url) = @_;
my($page) = get($url);
return $page;
}
################################


################################
#takes in a string, goes nuts on it removing all the html, and then returns it
sub stripHTML{
#now get some crazy shit going on.
my $html = '';
my $p = new HTML::Parser(
api_version => 3,
text_h => [ sub { $html .= shift }, 'text'],
);
$p->parse(shift);
$p->eof;
#print $html;
return $html;
}
################################


##########
## MAIN ##
#load the hashes
%adjHash = loadHashFromFile($adjFile);
%nounHash = loadHashFromFile($nounFile);
%verbHash = loadHashFromFile($verbFile);

##################################
#this should probably all really be in its own function... but whatever, not like this is graded
#calc the maxPostID to use.
$diff = time - $timeAtWriting;
if($diff > 86400){
$multiplier = $diff/86400;
$maxPostID = $maxPostID + (30 * $multiplier);#assume that there are 30 new posts every day... no exact, but that is about right
}
#connect to the site and get a thread page to scan for something to reply to
$okay = 0;
while($okay < 1){
#generate a random threadID between the lowend and highend.
#a number between zero and the diff, then add the min val
#if it outputs zero, then you are at the bottom value, if you hit the high end, then
#it is the max post. usually will be somewhere in between, which is good.
#add the int to make sure you aren't getting decimals
$threadID = int(rand($maxPostID-$minPostID)+$minPostID);
$content = grabPage($chatpage.$threadID);
#search for this string 'The administrator may have required you to'
#if that is there, then you hit a page that is dead - probably locked or moved.
#if that is the case, then just pick a new page
#the below would be just the if and do a negation check, but don't know how off the top of my head on that match.
if ($content =~ /The administrator may have required you to/ || length($content) < 21500){
$okay = 0;
}
#here we make sure it is indeed only posts on the chat board so as not to dick with other boards
elsif($content =~ /\&forumid\=11\"\>Chat\ \&\ Conversation\<\/a\>/){
$okay = 1;
}
else{
$okay = 0;
}
}
print $chatpage.$threadID,"\n";
##########

#now cut out chunks from the page
$startCut = '<a name="post';#at the end of that.
$endCut = '<a href="report.php?s=';#at the start of that
#loop and find where things are in the page
$pos = -1;
#go until you find what you are looking for
while (($pos = index($content,$startCut,$pos)) > -1) {
#now get where the end match is, minus its length.
$pos = $pos + length($startCut);
$pos2 = index($content,$endCut,$pos);
#now pull out that substring - starting at pos and stopping at pos2 minus the length of the endCut
$tempString = substr($content,$pos,$pos2-$pos);
$threadArr[++$#threadArr] = $tempString;
substr($content,0,$pos2) = '';
$pos++;
}
#match these strings, keep what is between them, and toss the rest.
$matchStart = '<p><font face="verdana, arial, helvetica" size="2" >';
$matchEnd = '</font></p>';
#now iterate through the array and get the strings so that they are just the text.
for($i=0;$i<$#threadArr+1;$i++){
$pos = 0;#these are from up above, but we are done with those
$pos2 = 0;
$pos = index($threadArr[$i],$matchStart,$pos);
$pos = $pos + length($matchStart);
#now get where the end match is
$pos2 = index($threadArr[$i],$matchEnd,$pos);
#now pull out that substring
$tempString = substr($threadArr[$i],$pos,$pos2-$pos);
$threadArr[$i] = $tempString;
}

#okay, now need to randomly choose a spot in the array - not a very good random, repeats a lot, but life is a tough thing
$workingPhrase = $threadArr[int(rand($#threadArr+1))];
#strip that string of all html
$workingPhrase = stripHTML($workingPhrase);
#then break that string up into words in an array
@wordArr = split(/ /,$workingPhrase);
#then iterate through them, and if they are in the hashes, save them in an array
$counter = 0;
foreach(@wordArr){
if($adjHash{$_}){
@adjArr = ('',
'',
'');#add strings in here that you want outputted for the adjective relation - the larger this is the better (i.e. hundreds of spots long... pain in the ass)
#randomly choose one of the above and add to the next array
$finalChoiceArr[++$#finalChoiceArr] = @adjArr[int(rand($#adjArr+1))];
}
elsif($nounHash{$_}){
#only do if it doesn't have any quotes in it
if(!/.*'.*/){
@nounArr = ('',
'',
'');#again, add strings, the more the better - add in $_ to the string to make it relate to what is in the thread
#randomly choose one of the above and add to the next array
$finalChoiceArr[++$#finalChoiceArr] = @nounArr[int(rand($#nounArr+1))];
}
}
elsif($verbHash{$_}){
@verbArr = ('',
'',
'');#again, add strings
#randomly choose one of the above and add to the next array
$finalChoiceArr[++$#finalChoiceArr] = @verbArr[int(rand($#verbArr+1))];
}
else{
#some strings that will show up rarely.
@elseArr = ('',
'',
'');#add strings here if it doesn't recognize any of the words in the thread
#randomly choose one of the above and add to the next array
#if the main array is empty or every tenth hit
if($#finalChoiceArr+1 == 0 || $counter % 10 == 0){
$finalChoiceArr[++$#finalChoiceArr] = @elseArr[int(rand($#elseArr+1))];
}
}
$counter++;
}
#pick a random one from the final array
$finalText = $finalChoiceArr[int(rand($#finalChoiceArr+1))];

#now post like a motherfucker
#this can't run until the cookies file is generated (see a few lines below) - once created, this is good to go
$ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new(file => "./cookies.txt",
autosave => 1));

#this is comment out all but the first run, which is just to grab the cookies so that this can make the server think it is dealing with a browser
#use this to fill cookies if you are having probs.
#my $req = POST 'http://boards.elitefitness.com/forum/member.php',
# [ action => 'login',
# s => '****',
# username => '****',
# password => '****'];

my $req = POST 'http://boards.elitefitness.com/forum/newreply.php',
[ s => '****',
action => 'postreply',
threadid => $threadID,
title => '',
iconid => '0',
mode => '0',
message => $finalText,
parseurl => 'yes',
signature => 'yes' ];

$ua->request($req)->as_string;
 
Top Bottom