Twitter Client Report


/ Published in: Perl
Save to your folder(s)

This report looks at the most recent Tweet from each person in your friends list and keeps track of which client they're using. It then prints out a report showing how many people use each client, with the most popular at the bottom.

Code is written to be run via the command line, but could be adapted to other uses.

Requires Net::Twitter, which is available via CPAN.


Copy this code and paste it in your HTML
  1. #!/usr/local/bin/perl
  2.  
  3. use strict;
  4. use Net::Twitter;
  5. use Getopt::Std;
  6. my %options = ();
  7. getopts('u:p:',\%options);
  8. my $twitter = Net::Twitter->new(
  9. username => $options{u},
  10. password => $options{p},
  11. );
  12.  
  13. if ( ! $options{u} || ! $options{p} ) {
  14. die "Usage: ./twitter_client_report.pl -u <twitter username> -p <twitter password>";
  15. }
  16.  
  17. my $verification = $twitter->verify_credentials();
  18.  
  19. my %clients = ();
  20. my $friends = $twitter->friends();
  21. foreach my $friend ( @{$friends} ) {
  22. $clients{$friend->{'status'}->{'source'}}++;
  23. }
  24.  
  25. foreach my $client ( sort { $clients{$a} <=> $clients{$b} } keys( %clients ) ) {
  26. print $clients{$client} . " - $client\n";
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.