Twitter Birthday Bot

bigchow

Junior Member
Joined
May 26, 2008
Messages
108
Reaction score
76
This script is freely available at sourceforge ineed:

http://sourceforge.net/projects/twitterbirthday/

It is only a single pl file:

Code:
#!/usr/bin/perl

use Net::Twitter;

# set your own username and password here
my $username = "";
my $password = "";

my $twit = Net::Twitter->new(username=>$username, password=>$password, source=>"web");

my $birthdaytext = "birthday";

# you can add more birthday messages here - @%s is the username 
my @birthdaymessages = (
  "@%s have a happy birthday!",
  "@%s happy birthday!",
  "@%s have a wonderful birthday!",
  "Happy Birthday, @%s!",
  "Have a Wonderful Birthday, @%s!"
);

# get names of people you've already sent a birthday tweet
my $prevbirthdaynames = {};
foreach my $updates (@{ $usertimeline }) {
  my $tweet = $updates->{'text'};
  if($tweet =~ /$birthdaytext/i and $tweet =~ "@") {
    ($prevbirthdayname) = ($tweet =~ /\@(\w*)\W/);
    $prevbirthdaynames->{$prevbirthdayname} = 1;
    print "prev name: ".$prevbirthdayname."\n";
  }
}

# get names of birthday people
my $birthdaynames = {};
foreach my $status (@{ $twit->friends_timeline() }) {
  my $text = $status->{'text'};
  if($text =~ /$birthdaytext/i and $text =~ "@") {
    ($birthdayname) = ($text =~ /\@(\w*)\W/);
    if(!$prevbirthdaynames->{$birthdayname}) {
      $birthdaynames->{$birthdayname} = 1;
    }
  }
}

# get friends
my $friends = {};
foreach my $friend (@{ $twit->friends() }) {
  $friends->{$friend->{'screen_name'}} = 1;
}

# if birthday person is a friend say happy birthday
my $nameslength = scalar keys %$birthdaynames;
if($nameslength > 0) {
  print "Your status was just updated with birthday tweets. Here are your tweets:"."\n\n";
}
foreach my $name (keys %$birthdaynames) {
  if($friends->{$name}) {
    my $birthdaymessage = sprintf(@birthdaymessages[rand @birthdaymessages], $name);
    $twit->update($birthdaymessage);
    print $birthdaymessage."\n";
  }
}

if($nameslength > 0) {
  print "\n"."Love,\n".$username."\n";
}

Somehow I couldn't get it working. The script breaks on line 3:

use Net::Twitter;

I have no knowledge of coding. Anybody can suggest a fix? It will be even greater if someone can convert it into a php file. :cool2:
 
Last edited:
You need to install the Net::Twitter module for perl.

If you are using Linux, start a terminal and type
Code:
sudo cpan -i Net::Twitter
and follow the instructions on screen.

If you use windows, I have no idea what you should do.
 
Back
Top