りむったーのついでに自分が欲しいと思ったやつ作りました。
実行できる環境作るのは頑張ってください。
りむったーみたいなのとほとんど同じです。
ソースはこんな感じ
#!/opt/local/bin/perl use strict; use warnings; use utf8; use Net::Twitter; print "---Start---\n"; print "---OAuth---"; # OAuth認証 my $consumer_key = ''; my $consumer_secret = ''; my $access_token = ''; my $access_token_secret = ''; my $twit = Net::Twitter->new( traits => ['API::REST', 'OAuth'], consumer_key => $consumer_key, consumer_secret => $consumer_secret, ); $twit->access_token( $access_token ); $twit->access_token_secret( $access_token_secret ); print "OK\n"; # 前回のフォロアー取得時のデータをファイルからハッシュに移す # スクリプトと同じ階層にファイルなかったら作成します use FindBin; use Fcntl; my $dir = $FindBin::Bin; my $FileName = 'following.txt'; my $FilePath = $dir. '/'. $FileName; # 最終更新日チェック my $filestat = ( stat( $FilePath ))[9]; ( my $sec, my $min, my $hour, my $mday, my $mon, my $year ) = localtime( $filestat ); $year = $year + 1900; $mon = $mon + 1; print 'last check : '.$year.'/'.$mon.'/'.$mday.' '.$hour.':'.$min.':'.$sec."\n"; print "---LoadData---"; # ファイルなかったら作って在ったら開いてリスト代入して sysopen( FH, $FilePath, O_RDONLY | O_CREAT ) or croak $!; my %old_following =(); foreach( <FH> ){ my @temp; @temp = split( ',', $_ ); chomp( @temp ); $old_following{ $temp[0] } = $temp[1]; } close( FH ); # ハッシュのキー( id )をリストに移して昇順にソート my @old_following_id = keys( %old_following ); @old_following_id = sort{ $a <=> $b }( @old_following_id ); print "OK\n---Getfollowing---"; # フォロアー取得 my $cursor = -1; my %new_following = (); while( $cursor != 0 ){ my $f = $twit->friends({ cursor => $cursor }); $cursor = $f->{ next_cursor }; foreach ( @{$f->{ users }} ){ $new_following{ $_->{ id }} = $_->{ screen_name }; } } my @new_following_id = keys( %new_following ); # ハッシュのキーをソート @new_following_id = sort{ $a <=> $b }( @new_following_id ); print "OK\n"; # リムーブチェック my @rename_usersID = (); print "\n=====rename=====\n"; foreach ( @old_following_id ){ if( exists( $new_following{ $_ } )){ # 在ったらscreen_nameも見て、変わってたらとりあえずリストに入れて # リムーブ表示のループ終わったら表示 if( $old_following{ $_ } ne $new_following{ $_ } ){ print $old_following{ $_ }."\t".'->'."\t".$new_following{ $_ }."\n"; } } } print "================\n"; print "---DataSave---"; # ファイルに取得したフォロアー一覧の書き込み open( FH, '>',$FilePath ) or die "$!"; foreach( @new_following_id ){ print FH $_.','.$new_following{ $_ }."\n"; } close( FH ); print "OK\n"; print '***ProgEND***'."\n"; __END__
こんな感じです。
Perlよく分かんないんでもっと効率いい書き方在ったら教えてください。
そんな感じです。