This queue is for tickets about the WWW-Myspace CPAN distribution.

Report information
The Basics
Id:
19808
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
olaf [...] wundersolutions.com
Requestors:
jason [...] eramsey.org
Cc:
AdminCc:

BugTracker
Severity:
Wishlist
Broken in:
0.47
Fixed in:
(no value)



Subject: add_friends sample script desired functionality
the example add_friends script is almost perfect for my purposes, except that I don't want to have to manage captcha requests as they come up... In trying to create my own script (close to successful, but I can't seem to get the module to return FC on captcha detection) I was trying to make it simply sleep for 12 hours and retry the last friend add... I would like add_friends to do that instead of showing the URL to the manual friend add... How is this accomplished? I've provided the script that I wrote that was nearly working... (also, is there a nice way to provide some kind of feedback on how long the script has left to sleep... I couldn't seem to figure that out either...) Thanks for all your help so far... #!/usr/bin/perl -w use strict; use Data::Dumper; use WWW::Myspace; use WWW::Myspace::FriendAdder; use List::Compare; $|++; my $username = edited; # string my $password = edited; # string my $cacheDir = $ENV{'HOME'} . "/.www-myspace"; # string default is "$ENV{'HOME'}/.www-myspace" my $cacheFile = 'login_cache'; # string default is "login_cache" my $autoLoginToggle = '1'; # [0|1] default is "1" my $excludeMyFriendsToggle = '0'; # [0|1] default is "0" my $interactiveToggle = '1'; # [0|1] default is "1" my $maxRequests = '250000'; # integer default is "50" my $profileTypes = 'all'; # [band|personal|all] default is "all" my $randomSleepToggle = '1'; # [0|1] default is "0" my $randomSleepMax = '30'; # integer default is "10" my $defaultSleepTimer = '43200'; # integer recommend a minimum of 43200 (12 hours) my $friendListFile = 'friendlist.txt'; my @newFriendsRough; my @newFriendsSuccess; my %newFriendsFailure; my $openLinkToggle = '0'; # [0|1] default is "0" my $webBrowser = '/usr/bin/firefox'; ########## # do not edit below this line ########## # decide whether or not the webbrowser should be opened when CAPTCHA is detected #print ("\n====================\nOpen CAPTCHA images in your web browser?\n[y/N] > "); #$_ = <STDIN>; #if ( /[Yy]/ ){ # $openLinkToggle = '1'; # print ( "\n====================\nCAPTCHA links will be opened in web browser located at $webBrowser.\n====================\n" ); #} #else { # $openLinkToggle = '0'; # print ( "\n====================\nCAPTCHA links will not be opened.\n====================\n" ); #} # grab user-defined variables my %myspace_params = ( account_name => $username, password => $password, cache_dir => $cacheDir, cache_file => $cacheFile, auto_login => $autoLoginToggle ); my %friendadder_params = ( exclude_my_friends => $excludeMyFriendsToggle, interactive => $interactiveToggle, max_count => $maxRequests, profile_type => $profileTypes, random_sleep => $randomSleepToggle, sleep => $randomSleepMax ); # create the cache directory if it doesn't already exist unless (-e $cacheDir) { my $tempspace = WWW::Myspace->new( \%myspace_params, ); print ( "FriendAdder cache directory does not exist. Creating in selected location ... " ); $tempspace->make_cache_dir; print ( "Succeeded.\n" ); } # establish connection to your Myspace account my $myspace = WWW::Myspace->new( \%myspace_params, ); # get prepared to add new friends to your Myspace account my $friendadder = WWW::Myspace::FriendAdder->new( $myspace, \%friendadder_params, ); # read list of friends from user-provided friendlist.txt file or die trying # format of friendlist.txt should be friendID_1<newline>friendID_2<newline> ... friendID_n open FRIENDLIST, $friendListFile or die ( "Friend List file $friendListFile is not found or could not be opened for read access.\t $!\n" ); while ( my $line = <FRIENDLIST> ) { my $linePretty = $line; $linePretty =~ s/(\r\n?|\n)//g; # clean up the extra line endings print ( "\nPoaching friends from $linePretty ... \n" ); push ( @newFriendsRough, $myspace->friends_from_profile ($line) ); print ( "\t\t\t\t ... Completed!\n" ); } close FRIENDLIST; # check for duplicate entries in @newFriendsRough and remove existing friends print ( "Gathering your friends ... \n" ); my @currentFriends = $myspace->get_friends; print ( "\t\t\t\t ... Completed!\n" ); my $friendcompare = List::Compare->new( { lists => [\@currentFriends, \@newFriendsRough], accelerated => 1 } ); my @newFriends = $friendcompare->get_complement; my $totalNewFriends = printf('%9s', @newFriends); # !!DEBUG!! a good something to try when troubleshooting # print Dumper(@newFriends); # let's add some friends, shall we? foreach my $newFriend ( @newFriends ) { print ( "Attempting to add friend $newFriend ... \n\n" ); #my $addStatus = $myspace->send_friend_request( $newFriend ); my $addStatus = $friendadder->send_friend_requests( $newFriend ); if ( $addStatus =~ /^P/ ) { print ( "\nSucceeded.\n" ); push ( @newFriendsSuccess, $newFriend ); } else { print ( "\nFailed with code $addStatus.\n" ); $newFriendsFailure{ $newFriend } = $addStatus; } if ( $addStatus eq 'FC' ) { print ( "\n\nCAPTCHA detected! Time to go to sleep ... \n\n" ); sleep $defaultSleepTimer; print ( "\n\n" ); # try to add friend again print ( "Attempting to add friend $newFriend ... " ); #$addStatus = $myspace->send_friend_request( $newFriend ); $addStatus = $friendadder->send_friend_requests( $newFriend ); if ( $addStatus =~ /^P/ ) { print ( "Succeeded.\n" ); push ( @newFriendsSuccess, $newFriend ); } else { print ( "Failed with code $addStatus.\n" ); $newFriendsFailure{ $newFriend } = $addStatus; } # $friendadder->send_friend_request( $newFriend ); # system("$webBrowser $myspace->captcha &"); } } # final report use Date::Simple; my $date = d8( today() ); my $failureFile = $date . "-failurefile.log"; my $totalNewFriendsSuccess = printf( '%9s', @newFriendsSuccess ); my $totalNewFriendsFailure = printf( '%9s', keys( % newFriendsFailure ) ); print ( "Unique IDs Attempted:\t\t$totalNewFriends\n\n" ); print ( "Friends Added Successfully:\t$totalNewFriendsSuccess\n" ); print ( "Friend Add Attempts Failed:\t$totalNewFriendsFailure\n\n" ); open ( FAILURELOG, '>', $failureFile ); while ( my ( $key, $value ) = each(%newFriendsFailure) ) { print FAILURELOG "$key\t$value\n"; } close FAILURELOG; print ( "Failures and reason codes have been exported to $failureFile\n" );
Okay... I figured it out... I'm not the best coder in the world, but I think you can get the idea... near as I can tell, it works... :o) This BOTH makes the process sleep for a configurable amount of time after detecting a CAPTCHA AND provides a progress bar so you have some idea how much time it's got left to sleep... Updated FriendAdder.pm: diff - c /usr/lib/perl5/site_perl/5.8.6/WWW/Myspace/FriendAdder.pm /home/rams yj/.cpan/build/WWW-Myspace-0.47/lib/WWW/Myspace/FriendAdder.pm *** /usr/lib/perl5/site_perl/5.8.6/WWW/Myspace/FriendAdder.pm Fri Jun 9 15:49:42 2006 --- /root/.cpan/build/WWW-Myspace- 0.47/lib/WWW/Myspace/FriendAdder.pm Wed May 31 21:57:40 2006 *************** *** 63,70 **** interactive => { default => 1 }, # try to be silent max_count => { default => 50 }, message_on_captcha => { default => 0 }, - sleep_on_captcha => { default => 0 }, - captcha_sleep_time => { default => 0 }, myspace => 0, profile_type => 0, random_sleep => { default => 0 }, --- 63,68 ---- *************** *** 479,520 **** $self->_report("message_on_captcha attempt...\n"); } - elsif ( $self->{'sleep_on_captcha'} ) { - use Term::ProgressBar; - - my $sleepTime = $self->{'captcha_sleep_time'}; - - print "\n\nCAPTCHA detected! Time to go to sleep ... \n\n"; - - my $progress = Term::ProgressBar->new( { name => 'Sleep', - count => $sleepTime, - ETA => 'linear' } ); - $progress->max_update_rate(1); - my $next_update = 0; - - for (0..$sleepTime) { - my $is_power = 0; - sleep 1; - - $next_update = $progress->update($_) if $_ > $next_update; - } - $progress->update($sleepTime) if $sleepTime >= $next_update; - - print "\n\n"; - - ( $status_code, $status ) = - $self->myspace->add_to_friends($id); - ++$adds if ( $status_code eq 'P' ); - ++$captcha; - - } else { $continue = undef; $self->_report("Exiting nicely..."); last; } ! } push ( @{ $code_report{$status_code} }, $id ); --- 477,490 ---- $self->_report("message_on_captcha attempt...\n"); } else { $continue = undef; $self->_report("Exiting nicely..."); last; } ! ! } push ( @{ $code_report{$status_code} }, $id ); Then there's a quick change to the add_friends sample script: # Set up the FriendAdder object my $adder = new WWW::Myspace::FriendAdder( myspace => $myspace, sleep => 60, random_sleep => 1, exclude_my_friends => 1, + sleep_on_captcha => 1, + captcha_sleep_time => 43200 );
Hey Jason, It only took me *over a year* to get back to you. My apologies. I was about to head out on tour with my band when your ticket initially came through. When I got back I started working 2 jobs and it kind of got out of hand from there. I'm just starting to get caught up on a lot of things now and I was able to have a look at your ticket. First off, thanks very much for taking the time to submit a patch and for explaining this so clearly. I've taken your code and I have built your idea into WWW::Myspace::FriendAdder.pm I implemented it today, so it will be tested and available in the next release. Thanks again. It was a great idea, but I just never found the time to sit down and code it. Since the option is now available via the module, it doesn't need to be coded into the sample script, but the idea is the same. I'd like to put your name in the acknowledgements of the module if you're amenable to that, but I need to know what it is. I can also include your email address or URL if you like. Just reply to this ticket if you'd like me to include your info. Again, my apologies for the wait, but it's a good idea and it was still worth implementing! All the best, Olaf On Fri Jun 09 18:05:28 2006, guest wrote:
Show quoted text
> Okay... I figured it out... I'm not the best coder in the world, but I > think you can get the idea... near as I can tell, it works... :o) This > BOTH makes the process sleep for a configurable amount of time after > detecting a CAPTCHA AND provides a progress bar so you have some idea > how much time it's got left to sleep... > > Updated FriendAdder.pm: > > diff - > c /usr/lib/perl5/site_perl/5.8.6/WWW/Myspace/FriendAdder.pm /home/rams > yj/.cpan/build/WWW-Myspace-0.47/lib/WWW/Myspace/FriendAdder.pm > *** /usr/lib/perl5/site_perl/5.8.6/WWW/Myspace/FriendAdder.pm Fri > Jun 9 15:49:42 2006 > --- /root/.cpan/build/WWW-Myspace- > 0.47/lib/WWW/Myspace/FriendAdder.pm Wed May 31 21:57:40 2006 > *************** > *** 63,70 **** > interactive => { default => 1 }, # try to be silent > max_count => { default => 50 }, > message_on_captcha => { default => 0 }, > - sleep_on_captcha => { default => 0 }, > - captcha_sleep_time => { default => 0 }, > myspace => 0, > profile_type => 0, > random_sleep => { default => 0 }, > --- 63,68 ---- > *************** > *** 479,520 **** > $self->_report("message_on_captcha attempt...\n"); > > } > - elsif ( $self->{'sleep_on_captcha'} ) { > - use Term::ProgressBar; > - > - my $sleepTime = $self->{'captcha_sleep_time'}; > - > - print "\n\nCAPTCHA detected! Time to go to sleep ... > \n\n"; > - > - my $progress = Term::ProgressBar->new( { name > => 'Sleep', > - count => > $sleepTime, > - ETA > => 'linear' } ); > - $progress->max_update_rate(1); > - my $next_update = 0; > - > - for (0..$sleepTime) { > - my $is_power = 0; > - sleep 1; > - > - $next_update = $progress->update($_) if $_ > > $next_update; > - } > - $progress->update($sleepTime) if $sleepTime >= > $next_update; > - > - print "\n\n"; > - > - ( $status_code, $status ) = > - $self->myspace->add_to_friends($id); > - ++$adds if ( $status_code eq 'P' ); > - ++$captcha; > - > - } > > else { > $continue = undef; > $self->_report("Exiting nicely..."); > last; > } > ! } > > push ( @{ $code_report{$status_code} }, $id ); > > --- 477,490 ---- > $self->_report("message_on_captcha attempt...\n"); > > } > > else { > $continue = undef; > $self->_report("Exiting nicely..."); > last; > } > ! > ! } > > push ( @{ $code_report{$status_code} }, $id ); > > > > Then there's a quick change to the add_friends sample script: > > # Set up the FriendAdder object > my $adder = new WWW::Myspace::FriendAdder( > myspace => $myspace, > sleep => 60, random_sleep => 1, > exclude_my_friends => 1, > + sleep_on_captcha => 1, > + captcha_sleep_time => 43200 > ); > >
Subject: RE: [rt.cpan.org #19808] add_friends sample script desired functionality
Date: Tue, 30 Oct 2007 17:18:42 -0400
To: "bug-WWW-Myspace@rt.cpan.org" <bug-WWW-Myspace@rt.cpan.org>
From: "Jason A. Ramsey" <ramz@districtignition.com>
that's very kind of you. point seems somewhat moot now with all the ridiculous anti-spam / anti-script mechanisms they've put in place on the site these days, but I don't mind being credited with the modification: Jason A. Ramsey < jason@eramsey.org > thank you! -- [ jR / ramz ] there is no path to greatness; greatness is the path speak: 703.628.2621 // write: ramz@districtignition.com see and hear: Ω // http://www.myspace.com/djramz
Show quoted text
________________________________________ From: Olaf Alders via RT [bug-WWW-Myspace@rt.cpan.org] Sent: Tuesday, October 30, 2007 4:55 PM To: Jason A. Ramsey Subject: [rt.cpan.org #19808] add_friends sample script desired functionality <URL: http://rt.cpan.org/Ticket/Display.html?id=19808 > Hey Jason, It only took me *over a year* to get back to you. My apologies. I was about to head out on tour with my band when your ticket initially came through. When I got back I started working 2 jobs and it kind of got out of hand from there. I'm just starting to get caught up on a lot of things now and I was able to have a look at your ticket. First off, thanks very much for taking the time to submit a patch and for explaining this so clearly. I've taken your code and I have built your idea into WWW::Myspace::FriendAdder.pm I implemented it today, so it will be tested and available in the next release. Thanks again. It was a great idea, but I just never found the time to sit down and code it. Since the option is now available via the module, it doesn't need to be coded into the sample script, but the idea is the same. I'd like to put your name in the acknowledgements of the module if you're amenable to that, but I need to know what it is. I can also include your email address or URL if you like. Just reply to this ticket if you'd like me to include your info. Again, my apologies for the wait, but it's a good idea and it was still worth implementing! All the best, Olaf On Fri Jun 09 18:05:28 2006, guest wrote:
> Okay... I figured it out... I'm not the best coder in the world, but I > think you can get the idea... near as I can tell, it works... :o) This > BOTH makes the process sleep for a configurable amount of time after > detecting a CAPTCHA AND provides a progress bar so you have some idea > how much time it's got left to sleep... > > Updated FriendAdder.pm: > > diff - > c /usr/lib/perl5/site_perl/5.8.6/WWW/Myspace/FriendAdder.pm /home/rams > yj/.cpan/build/WWW-Myspace-0.47/lib/WWW/Myspace/FriendAdder.pm > *** /usr/lib/perl5/site_perl/5.8.6/WWW/Myspace/FriendAdder.pm Fri > Jun 9 15:49:42 2006 > --- /root/.cpan/build/WWW-Myspace- > 0.47/lib/WWW/Myspace/FriendAdder.pm Wed May 31 21:57:40 2006 > *************** > *** 63,70 **** > interactive => { default => 1 }, # try to be silent > max_count => { default => 50 }, > message_on_captcha => { default => 0 }, > - sleep_on_captcha => { default => 0 }, > - captcha_sleep_time => { default => 0 }, > myspace => 0, > profile_type => 0, > random_sleep => { default => 0 }, > --- 63,68 ---- > *************** > *** 479,520 **** > $self->_report("message_on_captcha attempt...\n"); > > } > - elsif ( $self->{'sleep_on_captcha'} ) { > - use Term::ProgressBar; > - > - my $sleepTime = $self->{'captcha_sleep_time'}; > - > - print "\n\nCAPTCHA detected! Time to go to sleep ... > \n\n"; > - > - my $progress = Term::ProgressBar->new( { name > => 'Sleep', > - count => > $sleepTime, > - ETA > => 'linear' } ); > - $progress->max_update_rate(1); > - my $next_update = 0; > - > - for (0..$sleepTime) { > - my $is_power = 0; > - sleep 1; > - > - $next_update = $progress->update($_) if $_ > > $next_update; > - } > - $progress->update($sleepTime) if $sleepTime >= > $next_update; > - > - print "\n\n"; > - > - ( $status_code, $status ) = > - $self->myspace->add_to_friends($id); > - ++$adds if ( $status_code eq 'P' ); > - ++$captcha; > - > - } > > else { > $continue = undef; > $self->_report("Exiting nicely..."); > last; > } > ! } > > push ( @{ $code_report{$status_code} }, $id ); > > --- 477,490 ---- > $self->_report("message_on_captcha attempt...\n"); > > } > > else { > $continue = undef; > $self->_report("Exiting nicely..."); > last; > } > ! > ! } > > push ( @{ $code_report{$status_code} }, $id ); > > > > Then there's a quick change to the add_friends sample script: > > # Set up the FriendAdder object > my $adder = new WWW::Myspace::FriendAdder( > myspace => $myspace, > sleep => 60, random_sleep => 1, > exclude_my_friends => 1, > + sleep_on_captcha => 1, > + captcha_sleep_time => 43200 > ); > >
Hi Jason, It's not totally moot at this point, but it's not as easy as it once was! Best, Olaf On Tue Oct 30 17:20:59 2007, ramz@districtignition.com wrote:
Show quoted text
> that's very kind of you. point seems somewhat moot now with all the > ridiculous anti-spam / anti-script mechanisms they've put in place > on the site these days, but I don't mind being credited with the > modification: > > Jason A. Ramsey < jason@eramsey.org > > > thank > you! > > -- > > [ jR / ramz ] > there is no path to greatness; > greatness is the path > speak: 703.628.2621 // write: > ramz@districtignition.com > see and hear: Ω // > http://www.myspace.com/djramz > ________________________________________


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.