Recent Posts
Java | 5 sec ago
None | 17 sec ago
PHP | 22 sec ago
None | 34 sec ago
None | 47 sec ago
C | 50 sec ago
None | 1 min ago
None | 1 min ago
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Domain Reports
Please check out our new and improved Firefox Add-on. hide message
By NiggerGrinder on the 2nd of Jul 2009 08:38:22 AM Download | Raw | Embed | Report
  1. #! /usr/bin/perl
  2.  
  3. use strict;
  4. use XML::Simple;
  5. use LWP::UserAgent;
  6. use DBI;
  7.  
  8. # CONFIGURE THE BOT
  9.  
  10. my $twitter_username = "";
  11. my $twitter_password = "";
  12.  
  13. my $database_host = "";
  14. my $database_username = "";
  15. my $database_password = "";
  16. my $database_name = "";
  17.  
  18. my $search_word = "%23gorillapenis";
  19.  
  20. # CONFIGURATION ENDS HERE
  21.  
  22. # prepare MySQL
  23. my $DSN = "dbi:mysql:database=$database_name;host=$database_host;user=$database_username;password=$database_password";
  24.  
  25. my @write = ();
  26.  
  27. # search Twitter
  28. my @records = searchTwitter();
  29. if (scalar(@records) <= 0) {
  30.         die "No new tweets to post.\n";
  31.         exit;
  32. }
  33.  
  34. # post new tweets
  35. my $i = 0;
  36. foreach my $item (@records) {
  37.         my $statusid = $item->{statusid};
  38.         my $text =     $item->{text};
  39.         my $username = $item->{username};
  40.         my $handle   = $item->{handle};
  41.        
  42.         $text =~ s/'/''/g;
  43.        
  44.         my $tweet = "RT \@".$handle.": ".$text;
  45.                 $tweet =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
  46.                
  47.                 my $ua = new LWP::UserAgent;
  48.                 my $req = new HTTP::Request POST => 'http://twitter.com/statuses/update.xml';
  49.                 $req->authorization_basic($twitter_username, $twitter_password);
  50.                 $req->content("status=$tweet");
  51.  
  52.                 my $res = $ua->request($req);
  53.                
  54.                 if ($res->is_success) {
  55.                   print $res->content;
  56.             }
  57.                 else {
  58.                 print "ERROR POSTING TO TWITTER: " . $res->status_line, "\n";
  59.                         exit;
  60.                 }
  61.                
  62.         push (@write, $statusid);
  63.         sleep 59;
  64. }
  65.  
  66. # update database
  67. if($write[0] != '0') {
  68. my $dbh = DBI->connect($DSN);
  69.        
  70.         my $checkid = "insert into tabela values ('', '".$write[0]."')";
  71.         my $sth_check = $dbh->prepare($checkid);
  72.         my $rv = $sth_check->execute;
  73. }
  74.        
  75.  
  76. sub searchTwitter() {
  77.  
  78.  
  79.   my $dbh = DBI->connect($DSN);
  80.        
  81.         my $checkid = "select twitter from tabela order by id desc limit 1";
  82.         my $sth_check = $dbh->prepare($checkid);
  83.         my $rv = $sth_check->execute;
  84.        
  85.         my $tweetid = $sth_check->fetchrow();
  86.        
  87.         my @res = ();
  88.        
  89.         my $ua = new LWP::UserAgent;
  90.         my $req = new HTTP::Request GET => "http://search.twitter.com/search.atom?q=$search_word&rpp=100&since_id=$tweetid";
  91.         my $content = $ua->request($req)->content() or die "Error searching Twitter";
  92.  
  93.         my $xml = new XML::Simple (KeyAttr=>[]);
  94.        
  95.         my $data = $xml->XMLin($content);
  96.        
  97.         foreach my $item (@{$data->{entry}}) {
  98.                 my $rec = {};
  99.                
  100.                 if ($item->{title}) {
  101.                         $item->{author}{name} =~ /\s*(\S+)\s+\(/;
  102.         my $handle = $1;
  103.                         my $id = (split ':',$item->{id})[2];
  104.                        
  105.                         print "Search id: $id username: $handle\n";
  106.                         $rec->{'statusid'} = $id;
  107.                         $rec->{'text'} =     $item->{title};
  108.                         $rec->{'handle'}   = $handle;
  109.                         if($handle ne $twitter_username) { push (@res, $rec); }
  110.                 }
  111.         }
  112.        
  113.         return @res;
  114. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: