Subject: | Function Ideas and samples |
Per request, just some sample code i have for those functions i had
described in the forum.
You might want to download this page so the code will be more readable
note that these were taken straight out of another script which
handled an AIM bot, so each function handled multiple MySpace users
and accounts. Be carefull if your copy and pasting. This is mainly
just here for ideas.
#------------------------------------------------------
#post_bulletin posts a bulletin on myspace for the account holder
#------------------------------------------------------
sub post_bulletin{
$sender = shift;
$subject = shift;
$message = shift;
$account = decode_base64($people_myspace_names{$sender});
$pass = decode_base64($people_myspace_passes{$sender});
my ( $submitted, $res, $page );
my $myspace = WWW::Myspace->new ($account, $pass);
$my_id = $myspace->my_friend_id;
print " Users friend id is: $my_id\n";
if(($my_id) > "1"){
#its good
}else{
#bad username/pass
load_arrays();
send_message($sender, "It looks like your MySpace
username or password is incorrect. Please go to my page at $bot_page
and update it");
return;
}
# Try to get the message form
$res = $myspace->get_page( "${POST_BULLETIN_FORM}" );
# See if we can post or if there's an error.
if ( $res->is_success ) {
$page = $res->content;
$page =~ s/[ \t\n\r]+/ /g;
} else {
print "there was an html error (1)\n";
send_message($sender, "There was a MySpace internal
error. It was beyond my control. Sorry :(");
return;
}
# Take care "\n"s
$message =~ s/\\n/\n/gs;
# Submit the message
print " Submitting the first form... ";
$submitted = $myspace->submit_form( $res,
1, "",
{ 'subject'
=> "$subject",
'body' => "$message"
}
);
$page = $myspace->{current_page}->content;
$page =~ s/[ \t\n\r]+/ /g;
print "success!\n";
if ( $res->is_success ) {
$page = $res->content;
$page =~ s/[ \t\n\r]+/ /g;
}else{
print "there was an html error (2)\n";
send_message($sender, "There was a MySpace internal
error. It was beyond my control. Sorry :(");
return;
}
print " Submitting the confirmation form... ";
$confirmed = $myspace->submit_form( $myspace->{current_page},
1, "",{} );
print "success!\n";
$page = $myspace->{current_page}->content;
$page =~ s/[ \t\n\r]+/ /g;
# Return the result
if (! $confirmed ) {
print " there was an html error (3)\n";
send_message($sender, "There was a MySpace internal
error. It was beyond my control. Sorry :(");
return;
} elsif ( $page =~ /$VERIFY_BULLETIN_SENT/ ) {
print " SUCCESS ON BULLETIN!\n";
send_message($sender, "Your bulletin has successfully
been posted :) Remember... you might have to give it up to 5 minutes
before it shows up ;)");
return;
} else {
print " there was an html error (4)\n";
send_message($sender, "There was a MySpace internal
error. It was beyond my control. Sorry :(");
return;
}
print "Killing myspace\n\n";
#kill off the myspace class
$myspace = ''
}
Heres a littl snippet i use in a function that grabs the friends on
the top 8 list.....
#lets get the top 8 friends
$url = "http://home.myspace.com/index.cfm?fuseaction=user";
dbg (" Getting top 8 friends for $sender...\n");
$res=$myspace->get_page( $url );
$offset = index($res->content,"My Friend Space");
$content = substr($res->content,$offset) ;
my @mylist = $myspace->get_friends_on_page( $content );
dbg (" Got top 8 friends\n");
#got top 8
basically it just cuts all the data from the page until it sees "My
Friend Space", then pulls get_friends_on_page to it. Which im glad
get_friends_on_page uses raw content and not a url :) haha
#------------------------------------------------------
#myspace_stats will return if there are new posts,
#new comments, new pic comments, friend requests, event
#invites, blog comments, or blog subscription posts
#------------------------------------------------------
sub myspace_stats{
$sender = shift;
$account = decode_base64($people_myspace_names{$sender});
$pass = decode_base64($people_myspace_passes{$sender});
print ("$sender has requested MySpace stats\n");
dbg(" Starting MySpace class\n");
my $myspace = WWW::Myspace->new ($account, $pass);
dbg(" Getting users homepage\n");
$url = "http://home.myspace.com/index.cfm?fuseaction=user";
print "Getting MySpace status. Please be patient...\n";
$res=$myspace->get_page( $url );
$page = $res->content;
my $myspace_id = $myspace->my_friend_id;
our $NEW_MESSAGES='<div id="indicatorMail" class="show
indicator">';
our $NEW_COMMENTS='<div id="indicatorComments" class="show
indicator">';
our $NEW_PIC_COMMENTS='<div id="indicatorImageComments"
class="show indicator">';
our $NEW_FRIEND_REQ='<div id="indicatorFriendRequest"
class="show indicator">';
our $NEW_EVENT_INV='<div id="indicatorEvents" class="show
indicator">';
our $NEW_BLOG_COMMENTS='<div id="indicatorBlogComments"
class="show indicator">';
our $NEW_BLOG_SUB_POSTS='<div id="indicatorBlogs" class="show
indicator">';
if ( $page =~ /$NEW_MESSAGES/ ) {
$results .= "<br><a
href=\"http://mail.myspace.com/index.cfm?
fuseaction=mail.inbox\">MySpace</a>: <b>You Have New Messages!</b>";
dbg(" New Messages Found\n");
}else{
$results .= "<br><a
href=\"http://mail.myspace.com/index.cfm?
fuseaction=mail.inbox\">MySpace</a>: 0 new messages";
dbg(" No New Messages\n");
}
if ( $page =~ /$NEW_COMMENTS/ ) {
$results .= "<br><a
href=\"http://comments.myspace.com/index.cfm?
fuseaction=user.HomeComments&friendID=".$myspace_id."\">MySpace</a>:
<b>You Have New Comments!</b>";
dbg(" New Comments Found\n");
}else{
$results .= "<br><a
href=\"http://comments.myspace.com/index.cfm?
fuseaction=user.HomeComments&friendID=".$myspace_id."\">MySpace</a>: 0
new comments";
dbg(" No New Comments\n");
}
if ( $page =~ /$NEW_PIC_COMMENTS/ ) {
$results .= "<br><a
href=\"http://comments.myspace.com/index.cfm?
fuseaction=user.viewPicture&friendID=".$myspace_id."\">MySpace</a>:
<b>You Have New Picture Comments!</b>";
dbg(" New Pic Comments Found\n");
}else{
$results .= "<br><a
href=\"http://comments.myspace.com/index.cfm?
fuseaction=user.viewPicture&friendID=".$myspace_id."\">MySpace</a>: 0
new pic comments";
dbg(" No New Pic Comments\n");
}
.
.
.
.
i think you get the idea :)
return $results;