Skip Menu |

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

Report information
The Basics
Id: 18055
Status: resolved
Worked: 30 min
Priority: 0/
Queue: WWW-Myspace

People
Owner: GRANTG [...] cpan.org
Requestors: olaf [...] vilerichard.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: return codes patch
Date: Tue, 7 Mar 2006 23:18:46 -0500
To: bug-www-myspace [...] rt.cpan.org
From: Olaf Alders <olaf [...] vilerichard.com>
Hi, Here's a little patch for send_friend_request The only difference is if you call it in list mode, you get a full response message as well as the code: my ($response_code, $response_message) = $myspace->send_friend_request ( $id ); My editor doesn't use tabs, so I hope it doesn't look too messed on your end: 1855a1856,1866 Show quoted text
> my %status_codes = ( > > FF => 'Failed, this person is already your friend.', > FN => 'Failed, network error (couldn\'t get the page,
etc).', Show quoted text
> FP => 'Failed, you already have a pending friend request
for this person', Show quoted text
> FC => 'Failed, CAPTCHA response requested.', > P => 'Passed! Verification string received.', > F => 'Failed, verification string not found on page
after posting.', Show quoted text
> > ); >
1859a1871,1872 Show quoted text
> my $return_code = undef; >
1862c1875 < return "FN"; --- Show quoted text
> $return_code = 'FN';
1865,1890c1878,1909 < my $page = $self->current_page->content; < $page =~ s/[ \t\n\r]+/ /g; < < # Check for success < if ( $page =~ /An email has been sent to the user/i ) { < return "P"; < } < < # Check for "already your friend" < if ( $page =~ /already your friend/i ) { < return "FF"; < } < < # Check for pending friend request < if ( $page =~ /pending friend request/i ) { < return "FP"; < } < < # Check for CAPTCHA < if ( $page =~ /CAPTCHA/ ) { < return "FC"; < } < < # Failed. < return "F"; < --- Show quoted text
> else { > > my $page = $self->current_page->content; > $page =~ s/[ \t\n\r]+/ /g; > > # Check for success > if ( $page =~ /An email has been sent to the user/i ) { > $return_code = 'P'; > } > > # Check for "already your friend" > elsif ( $page =~ /already your friend/i ) { > $return_code = 'FF'; > } > > # Check for pending friend request > elsif ( $page =~ /pending friend request/i ) { > $return_code = 'FP'; > } > > # Check for CAPTCHA > elsif ( $page =~ /CAPTCHA/ ) { > $return_code = 'FC'; > } > > # Failed. > unless ($return_code) { > $return_code = 'F'; > } > } > > return $return_code, $status_codes{$return_code};
If you don't find it useful, I won't be offended of course! BTW, here's what I've been doing to get around the CAPTCHA stuff. I coded this before I patched the status response: use IO::Prompt; my %status_codes = ( FF => 'Failed, this person is already your friend.', FN => 'Failed, network error (couldn\'t get the page, etc).', FP => 'Failed, you already have a pending friend request for this person', FC => 'Failed, CAPTCHA response requested.', P => 'Passed! Verification string received.', F => 'Failed, verification string not found on page after posting.', ); my $sleep = 10; # pass a list of friend ids to this sub sub friend_request { my @ids = @_; foreach my $id ( @ids ) { my $status = $myspace->send_friend_request( $id ); ++$status{$status}; print "$id:\t$status\n"; if ($status eq 'FC') { print "captcha response. please fill in the form at the following url before continuing.\n"; print "\n\nhttp://collect.myspace.com/index.cfm? fuseaction=invite.addfriend_verify&friendID=$id\n\n"; my $continue = prompt "Continue? (y/n)\n", -yn; unless ($continue) { print "exiting nicely."; last; } } sleep $sleep; } print "Final status report...\n\n######################\n"; foreach my $key (keys %status_codes) { if (exists $status{$key} ) { print "$status{$key} $status_codes{$key} ($key)\n"; } } } Maybe it would be helpful to add an "interactive" method that could do this sort of thing to help sort out the CAPTCHA stuff. In this context $myspace->captcha was always coming back empty, so I use this as my workaround. Best, Olaf -- Olaf Alders olaf@vilerichard.com http://www.vilerichard.com -- pop tunes http://cdbaby.com/cd/vilerichard
Beautiful. Patch applied (which was a bit tricky as I'm on version 0.31 here :). I love the CAPTCHA workaround. I think I like that better than $myspace->captcha in fact (which doesn't do much good, really). Didn't occur to me to just have them go do that one and let the program continue from there. D'oh. Grant
Olaf, I'm adding you to the "Thanks to" section of the docs. Would you like me to include a URL, and if so which one? Grant
Subject: Re: [rt.cpan.org #18055] return codes patch
Date: Wed, 8 Mar 2006 07:20:55 -0500
To: bug-WWW-Myspace [...] rt.cpan.org
From: Olaf Alders <olaf [...] vilerichard.com>
Hi Grant, Thanks very much -- I appreciate that. My scripting url is: www.wundersolutions.com If you could use that one, that would be great! All the best, Olaf On 8-Mar-06, at 5:51 AM, via RT wrote: Show quoted text
> Olaf, > > I'm adding you to the "Thanks to" section of the docs. Would you > like me to include a URL, and > if so which one? > > Grant >
-- Olaf Alders olaf@vilerichard.com http://www.vilerichard.com -- pop tunes http://cdbaby.com/cd/vilerichard
Subject: Re: [rt.cpan.org #18055] return codes patch
Date: Wed, 8 Mar 2006 07:34:31 -0500
To: bug-WWW-Myspace [...] rt.cpan.org
From: Olaf Alders <olaf [...] vilerichard.com>
Hi Grant, I'm glad to hear it was helpful. Just to let you know, what I've been using the script for is to find a band that has a similar sound to mine and then to message the friends of that band with friend requests. I've been about to go from 42 friends on Sunday 234 friends as of right now and I'd made a lot of positive connections along the way. Still have another 100 or so request awaiting approval and it has saved me *a lot* of clicking along the way. A lot of people have been listening to the tunes and I'm planning to use this as a resource before the band goes on tour this summer. (As an aside, I had a look at the guts of the module while I was doing the patch and I wonder if some of that stuff might be a bit easier using WWW::Mechanize? That's just a thought. I'm not sure if you have a specific reason for not using that module, but I've just started using it recently and most things have become much easier. Getting a list of links on the page is dead easy, for example.) One thing I wanted to ask you about is getting a list of friends. What I've been doing is taking an artist and going to their first page of friends. I then do this: my $res = $myspace->get_page($page); my @friends = $myspace->get_friends_on_page( $res->content ); That gets me about 40 friends but I need to add an url for each friends page, because they may have 12 pages of friends. At least that's the way I've been doing it. It's probably not the most elegant. Is there a way with the present module to get all of the friends for any given artist? I know you've got it set up for the groups and that you can get all of your own friends, but I didn't see a way to get someone else's friends. If I'm missing something, could you let me know? If you'd like a patch for something like that, I can go ahead and look into it as it would save me huge amounts of time. Thank you for being so responsive -- it's a really great module that you've got here! All the best, Olaf On 8-Mar-06, at 5:49 AM, via RT wrote: Show quoted text
> Beautiful. Patch applied (which was a bit tricky as I'm on version > 0.31 here :). I love the > CAPTCHA workaround. I think I like that better than $myspace-
> >captcha in fact (which doesn't
> do much good, really). Didn't occur to me to just have them go do > that one and let the program > continue from there. D'oh. > > Grant >
-- Olaf Alders olaf@vilerichard.com http://www.vilerichard.com -- pop tunes http://cdbaby.com/cd/vilerichard
Subject: Re: [rt.cpan.org #18055] return codes patch
Date: Wed, 8 Mar 2006 12:03:23 -0800
To: bug-WWW-Myspace [...] rt.cpan.org
From: Grant Grueninger <grantg [...] spamarrest.com>
Hi Olaf, Responses in-line below. On Mar 8, 2006, at 4:34 AM, Olaf Alders via RT wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=18055 > > > Hi Grant, > > I'm glad to hear it was helpful. Just to let you know, what I've > been using the script for is to find a band that has a similar sound > to mine and then to message the friends of that band with friend > requests. I've been about to go from 42 friends on Sunday 234 > friends as of right now and I'd made a lot of positive connections > along the way. Still have another 100 or so request awaiting > approval and it has saved me *a lot* of clicking along the way. A > lot of people have been listening to the tunes and I'm planning to > use this as a resource before the band goes on tour this summer.
Good idea. I've been finding fan groups of similar-sounding mainstream artists and using message_group to contact the members. Show quoted text
> > (As an aside, I had a look at the guts of the module while I was > doing the patch and I wonder if some of that stuff might be a bit > easier using WWW::Mechanize? That's just a thought. I'm not sure if > you have a specific reason for not using that module, but I've just > started using it recently and most things have become much easier. > Getting a list of links on the page is dead easy, for example.)
I do plan to move to WWW::Mechanize. The module started out as a very simple script and all I needed was something to handle a form, so I searched CPAN and found HTTP::Request::Form. Then the script grew into a module, and outgrew HTTP::Request::Form. Show quoted text
> > One thing I wanted to ask you about is getting a list of friends. > What I've been doing is taking an artist and going to their first > page of friends. I then do this: > > my $res = $myspace->get_page($page); > my @friends = $myspace->get_friends_on_page( $res->content ); > > That gets me about 40 friends but I need to add an url for each > friends page, because they may have 12 pages of friends. At least > that's the way I've been doing it. It's probably not the most > elegant. Is there a way with the present module to get all of the > friends for any given artist? I know you've got it set up for the > groups and that you can get all of your own friends, but I didn't see > a way to get someone else's friends. If I'm missing something, could > you let me know? If you'd like a patch for something like that, I > can go ahead and look into it as it would save me huge amounts of > time. Thank you for being so responsive -- it's a really great > module that you've got here! >
I thought that would be a simple change, so 2 hours ago I started making the simple change... Anyway, wasn't quite as simple as I thought, but it's done now. New "friends_from_profile" method will be in version 0.31. Show quoted text
> All the best, > > Olaf > > > > On 8-Mar-06, at 5:49 AM, via RT wrote: >
>> Beautiful. Patch applied (which was a bit tricky as I'm on version >> 0.31 here :). I love the >> CAPTCHA workaround. I think I like that better than $myspace-
>>> captcha in fact (which doesn't
>> do much good, really). Didn't occur to me to just have them go do >> that one and let the program >> continue from there. D'oh. >> >> Grant >>
> > -- > Olaf Alders > olaf@vilerichard.com > > http://www.vilerichard.com -- pop tunes > http://cdbaby.com/cd/vilerichard > > > >
-- Grant Grueninger Commercial Systems Corporation http://www.cscorp.com/ 818-760-1649
Subject: Re: [rt.cpan.org #18055] return codes patch
Date: Wed, 8 Mar 2006 12:06:25 -0800
To: bug-WWW-Myspace [...] rt.cpan.org
From: Grant Grueninger <grantg [...] spamarrest.com>
Done. On Mar 8, 2006, at 4:21 AM, Olaf Alders via RT wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=18055 > > > Hi Grant, > > Thanks very much -- I appreciate that. My scripting url is: > www.wundersolutions.com If you could use that one, that would be > great! > > All the best, > > Olaf > > On 8-Mar-06, at 5:51 AM, via RT wrote: >
>> Olaf, >> >> I'm adding you to the "Thanks to" section of the docs. Would you >> like me to include a URL, and >> if so which one? >> >> Grant >>
> > -- > Olaf Alders > olaf@vilerichard.com > > http://www.vilerichard.com -- pop tunes > http://cdbaby.com/cd/vilerichard > > > >
-- Grant Grueninger Commercial Systems Corporation http://www.cscorp.com/ 818-760-1649
Subject: Re: [rt.cpan.org #18055] return codes patch
Date: Wed, 8 Mar 2006 15:14:12 -0500
To: bug-WWW-Myspace [...] rt.cpan.org
From: Olaf Alders <olaf [...] vilerichard.com>
Hi Grant, Show quoted text
> > I do plan to move to WWW::Mechanize. The module started out as a > very simple script and all I needed was something to handle a form, > so I searched CPAN and found HTTP::Request::Form. Then the script > grew into a module, and outgrew HTTP::Request::Form.
That makes sense. Just thought I'd throw in my 2 cents. I used to use LWP for everything, but this mech stuff is great. Show quoted text
>>
> > I thought that would be a simple change, so 2 hours ago I started > making the simple change... > Anyway, wasn't quite as simple as I thought, but it's done now. New > "friends_from_profile" method > will be in version 0.31.
What can I say? That's *excellent*. Thanks very much. I'll look out for the new release! Best, Olaf -- Olaf Alders olaf@vilerichard.com http://www.vilerichard.com -- pop tunes http://cdbaby.com/cd/vilerichard
Subject: Re: [rt.cpan.org #18055] return codes patch
Date: Thu, 9 Mar 2006 00:18:54 -0800
To: bug-WWW-Myspace [...] rt.cpan.org
From: Grant Grueninger <grantg [...] spamarrest.com>
Hi again, Would you mind if I included a slightly updated version of your friend adding script in the distribution? It would be called "add_friends" and would take a friendID as its argument, then get that profile's friends and send friend requests (basically using the subroutine code you posted in RT with a bit more verbosity added). Grant On Mar 8, 2006, at 12:15 PM, Olaf Alders via RT wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=18055 > > > Hi Grant, >
>> >> I do plan to move to WWW::Mechanize. The module started out as a >> very simple script and all I needed was something to handle a form, >> so I searched CPAN and found HTTP::Request::Form. Then the script >> grew into a module, and outgrew HTTP::Request::Form.
> > That makes sense. Just thought I'd throw in my 2 cents. I used to > use LWP for everything, but this mech stuff is great. >
>>>
>> >> I thought that would be a simple change, so 2 hours ago I started >> making the simple change... >> Anyway, wasn't quite as simple as I thought, but it's done now. New >> "friends_from_profile" method >> will be in version 0.31.
> > What can I say? That's *excellent*. Thanks very much. I'll look > out for the new release! > > Best, > > Olaf > -- > Olaf Alders > olaf@vilerichard.com > > http://www.vilerichard.com -- pop tunes > http://cdbaby.com/cd/vilerichard > > > >
-- Grant Grueninger Commercial Systems Corporation http://www.cscorp.com/ 818-760-1649
Subject: Re: [rt.cpan.org #18055] return codes patch
Date: Thu, 9 Mar 2006 10:24:55 -0500
To: bug-WWW-Myspace [...] rt.cpan.org
From: Olaf Alders <olaf [...] vilerichard.com>
Hi Grant, If it's helpful to you in any way, please feel free to use/modify/ strip it down etc. If you use the prompt line, you may want to add the -onechar flag: my $continue = prompt "Continue? (y/n) ", -onechar, -yn; That will allow the script to continue after a y or n without waiting for the user to hit enter/return. Glad I can help in a small way. Best, Olaf On 9-Mar-06, at 3:19 AM, grantg@spamarrest.com via RT wrote: Show quoted text
> Hi again, > > Would you mind if I included a slightly updated version of your > friend adding script in the distribution? > > It would be called "add_friends" and would take a friendID as its > argument, then get that profile's friends and send friend requests > (basically using the subroutine code you posted in RT with a bit more > verbosity added). > > Grant > > On Mar 8, 2006, at 12:15 PM, Olaf Alders via RT wrote: >
>> >> <URL: http://rt.cpan.org/Ticket/Display.html?id=18055 > >> >> Hi Grant, >>
>>> >>> I do plan to move to WWW::Mechanize. The module started out as a >>> very simple script and all I needed was something to handle a form, >>> so I searched CPAN and found HTTP::Request::Form. Then the script >>> grew into a module, and outgrew HTTP::Request::Form.
>> >> That makes sense. Just thought I'd throw in my 2 cents. I used to >> use LWP for everything, but this mech stuff is great. >>
>>>>
>>> >>> I thought that would be a simple change, so 2 hours ago I started >>> making the simple change... >>> Anyway, wasn't quite as simple as I thought, but it's done now. New >>> "friends_from_profile" method >>> will be in version 0.31.
>> >> What can I say? That's *excellent*. Thanks very much. I'll look >> out for the new release! >> >> Best, >> >> Olaf >> -- >> Olaf Alders >> olaf@vilerichard.com >> >> http://www.vilerichard.com -- pop tunes >> http://cdbaby.com/cd/vilerichard >> >> >> >>
> > > -- > Grant Grueninger > Commercial Systems Corporation > http://www.cscorp.com/ > 818-760-1649 > > >
-- Olaf Alders olaf@vilerichard.com http://www.vilerichard.com -- pop tunes http://cdbaby.com/cd/vilerichard
From: olaf [...] vilerichard.com
Hi Grant, Sorry, my patch introduced a bug. I've got the return values in the wrong order so, if it's not called in list context, it returns the status error message rather than the status code. There are 2 ways to fix this. #1 would be to reverse the order of the messages in the return statement, but that makes it a bit goofy when you call it in list context (I would expect the code to come before the message #2 do contextual returns. I've provided a patch to do this and I've tested it out. I must have been sloppy last time and not done a proper test on the final version. Here you go (with my apologies). Also, I've left a couple of notes on AnnoCPAN about the new function. It works really well. Thanks for adding it! --- Myspace.pm.orig 2006-03-13 15:12:48.000000000 -0500 +++ Myspace.pm 2006-03-13 15:15:56.000000000 -0500 @@ -23,6 +23,7 @@ # Libraries we use use Carp; +use Contextual::Return; use URI::URL; use LWP::UserAgent; use HTTP::Request; @@ -2168,7 +2169,10 @@ } } - return $return_code, $status_codes{$return_code}; + return ( + LIST { $return_code, $status_codes{$return_code} } + STR { $return_code } + ); } =head2 send_friend_requests( @friend_ids )
From: olaf [...] vilerichard.com
I should also add (though you'll see it in the patch) that this requires the Contextual::Return module to be installed on the user's machine. I picked this up in Damian's "Perl Best Practices". Seems to be quite handy. This is the first time I've used it, but it makes a lot of sense. On Mon Mar 13 15:26:18 2006, guest wrote: Show quoted text
> Hi Grant, > > Sorry, my patch introduced a bug. I've got the return values in the > wrong order so, if it's not called in list context, it returns the > status error message rather than the status code. There are 2 ways to > fix this. > > #1 would be to reverse the order of the messages in the return > statement, but that makes it a bit goofy when you call it in list > context (I would expect the code to come before the message > > #2 do contextual returns. I've provided a patch to do this and I've > tested it out. I must have been sloppy last time and not done a proper > test on the final version. Here you go (with my apologies). Also, I've > left a couple of notes on AnnoCPAN about the new function. It works > really well. Thanks for adding it! > > --- Myspace.pm.orig 2006-03-13 15:12:48.000000000 -0500 > +++ Myspace.pm 2006-03-13 15:15:56.000000000 -0500 > @@ -23,6 +23,7 @@ > # Libraries we use > > use Carp; > +use Contextual::Return; > use URI::URL; > use LWP::UserAgent; > use HTTP::Request; > @@ -2168,7 +2169,10 @@ > } > } > > - return $return_code, $status_codes{$return_code}; > + return ( > + LIST { $return_code, $status_codes{$return_code} } > + STR { $return_code } > + ); > } > > =head2 send_friend_requests( @friend_ids )
Thanks, good catch. Applied. I tried reproducing the bug and at first couldn't, then I realized that out of habit I was still calling the method in a list context... Oops.