[Perl]ATNDの参加者IDをTwitterでフォローする

add to hatena hatena.comment (0) add to del.icio.us (0) add to livedoor.clip (0) add to Yahoo!Bookmark (0) Total: 0 2010 年 2 月 25 日 by: baron

30分ででっち上げたのでXMLのパースとかTwitterIDの正規表現とかいろいろ問題がありますが、何となく動いたので。
ATNDのID = TwitterのIDじゃないので誤フォローもありえます。

PERL:
  1. use strict;
  2. use warnings;
  3. use Net::Twitter;
  4. use LWP::Simple;
  5. use XML::Simple;
  6. use URI::Escape;
  7.  
  8. # TwitterのID/PW
  9. my $twitter = new Net::Twitter(
  10.     username => 'username',
  11.     password => 'password',
  12. );
  13.  
  14. # ATNDのイベントID
  15. my $event_id = 1;
  16.  
  17. my $uri = "http://api.atnd.org/events/users/?event_id=$event_id";
  18.  
  19. my $xml = LWP::Simple::get($uri) or die "cannot get content from $uri";
  20. my $data = XML::Simple->new->XMLin($xml);
  21.  
  22. for (@{$data->{events}{event}{users}{user}}) {
  23.     $twitter->create_friend(uri_escape_utf8 $_->{nickname}) if $_->{nickname} =~ /[A-Za-z0-9_]+/;
  24. }

Filed under: Perl,プログラム
タグ: ,

Leave a Reply

アナログ