|
|
||
svn http://coderepos.org/share/browser/lang/perl/Net-Twitter-Diff
use Net::Twitter::Diff; my $diff = Net::Twitter::Diff->new( username => '******' , password => '******'); my $res = $diff->diff(); # get screen_names who you are not following but they are. print Dumper $res->{not_following}; # get screen_names who they are not following but you are. print Dumper $res->{not_followed}; # get screen_names who you are following them and also they follow you. print Dumper $res->{communicated}; my $res2 = $diff->comp_following( 'somebody_twitter_name' ); # only you are following print Dumper $res2->{only_me} ; # you are not following but somebody_twitter_name are following print Dumper $res2->{not_me} ; # both you and somebody_twitter_name are following print Dumper $res2->{share} ; # If you want , this module use Net::Twitter as base so you can use methods Net::Twitter has. $diff->update('My current Status');
# この2つは基本的に、Net::Twitter->following() , Net::Twitter->followers()と同じだが、100件以上取得できる。 my $a = $diff->xfollowing(); my $b = $idff->xfollowers();
最近このモジュールばっかで、飽き気味だけど思いついたので作った。
指定したURLの中のTwitterページへのリンクがあれば、そのユーザを見つけて、followできるようにした。
ソースはここね。バージョン微妙に上がってます。0.01_06が必要です。
svn co http://svn.coderepos.org/share/lang/perl/Net-Twitter-FriendFinder/trunk/
or
cpan install Net::Twitter::FriendFinder
use Net::Twitter::FriendFinder; my $tf = Net::Twitter::FriendFinder->new({ setting => { username => 'tomyhero', password => '*******', filter_already_followers => 1, # 既に登録しているユーザは対象から外す }, from => { 'URL' => {}, } }); $tf->search( 'http://twitter.g.hatena.ne.jp/keyword/Friends%e7%99%bb%e9%8c%b2%e3%81%94%e8%87%aa%e7%94%b1%e3%81%ab%20Part3' ); $tf->show(); #$tf->follow(); # 登録はしない
OK!293人も見つかったよ!
1時間に70回しかリクエストできないので、全員を一度に登録する為には、sleepを使う。
時間はかかるけど、以下でたぶんできる。ちなみに,clientを立ち上げてると、それもリクエストをしているので、制限に引っかかるとおもう。
use Net::Twitter::FriendFinder; my $tf = Net::Twitter::FriendFinder->new({ setting => { username => 'tomyhero', password => '*******', filter_already_followers => 1, # 既に登録しているユーザは対象から外す on_echo => 1, sleep => 60, # 1分休む }, from => { 'URL' => {}, } }); $tf->search( 'http://twitter.g.hatena.ne.jp/keyword/Friends%e7%99%bb%e9%8c%b2%e3%81%94%e8%87%aa%e7%94%b1%e3%81%ab%20Part3' ); $tf->show(); $tf->follow();
limitをつけて10人ずつ登録する。これを、時間をあけて数回実行すれば、そのうちコンプリートすると思う。
use Net::Twitter::FriendFinder; my $tf = Net::Twitter::FriendFinder->new({ setting => { username => 'tomyhero', password => '*******', filter_already_followers => 1, # 既に登録しているユーザは対象から外す on_echo => 1, limit => 10, }, from => { 'URL' => {}, } }); $tf->search( 'http://twitter.g.hatena.ne.jp/keyword/Friends%e7%99%bb%e9%8c%b2%e3%81%94%e8%87%aa%e7%94%b1%e3%81%ab%20Part3' ); $tf->show(); $tf->follow();
実行してみた。
Filter Userは既にfollowしているユーザだ。
$tf->search( $url )
http://coderepos.org/share/browser/lang/perl/Net-Twitter-FriendFinder
svn co http://svn.coderepos.org/share/lang/perl/Net-Twitter-FriendFinder/trunk/
use Net::Twitter::FriendFinder; my $tf = Net::Twitter::FriendFinder->new({ setting => { filter_already_followers => 1, username=> '*******', password=> '*******', on_echo => 1, sleep => 60, }, from => { 'Google' => { lang=>'ja'}, } }); $tf->search( 'えろ' ); $tf->show(); #$tf->follow();
Clients are allowed 70 requests per 60 sixty minute time period, starting from their first request. This is enough to make just over one request per minute, per hour, which should meet the needs of most applications. Rate limiting applies only to authenticated API requests; requests for the public timeline do not count. POST requests (ex: updating status, sending a direct message) also do not count against the rate limit.
APIの使用には(public timeline , update status, direct messeage以外)は、一時間中70回までしかリクエストできない。
この対応として、sleepを入れれるようにしたのと、無駄なリクエストを減らす為に既にfollowしている人は省けるようにしました。
friends
Returns up to 100 of the authenticating user's friends who have most recently updated, each with current status inline. It's also possible to request another user's recent friends list via the id parameter b
最近更新があった順番に100件のデータを返す。
これは、結構困ったのですが、page パラメータを指定すると次の100件がとれるようです。オフィシャルでは書かれていないです。これは、Net::Twitterでは対応できないので、無理矢理対応するようにしました。
また、このAPIで取得した情報はキャッシュからのようで、最近にfollowしたユーザが反映されるまでラグがあります。
bookmarkより
nyancy1011 twitter検索じゃだめなの?
そんなサイトがあったのか!Thanks for your info!!
つい、プログラム作ってしまった。
追記:インターフェイスを変更しました。sorry.
http://twitter.g.hatena.ne.jp/tomyhero/20071113
follower , follwoing のdiff情報取得をそれなりに簡単にできます。それだけです。
http://coderepos.org/share/browser/lang/perl/Net-Twitter-Diff
svn co http://svn.coderepos.org/share/lang/perl/Net-Twitter-Diff/trunk/
調べるだけなら、以下のすばらしいサイトを使用した方が楽。
Twitter Friends Analyzer -> http://tw.muumoo.jp/torchy.html
use Net::Twitter::Diff; use Data::Dumper; my $diff = Net::Twitter::Diff->new(); $diff->diff( { username => 'tomyhero' , password => '******' } ); # get screen_names who you are not following but they are. print "followingしてない\n"; print Dumper $diff->not_following(); # get screen_names who they are not following but you are. print "followedされてない\n"; print Dumper $diff->not_followed(); # get screen_names who you are following them and also they follow you. print "会話が成り立つかも\n"; print Dumper $diff->communicated();
結果 (followingしていない方は、なぜか当時やろうとしたけどfollowできなかった気がする。)
followingしてない
$VAR1 = [
'LouiZoot',
'Naney',
'AzureStone',
'noboribotan',
'cubevoice',
'oppappiz'
];
followedされてない
$VAR1 = [
'larsen',
'miyagawa',
'geek',
'srushe',
'MikeG514',
'tokuhirom',
'jshirley',
'dous',
'net_twitter',
'londonpm',
'techstep',
'burningpaper',
'mindgap',
'voxefx',
'account',
'mendel',
'pckwan',
'perezvon',
'somafire',
'hatebu',
'neuralnoise',
'otsune',
'nyarla',
'sweetlove',
'Yappo',
'gyuque',
'jmworks',
'pal9999',
'jun_ichiro',
'fbis',
'tsuda',
'T0RU',
'umhr',
'anontwit',
'tatsugogo55',
't_muto',
'perl',
'spequer',
'cojix',
'camtarn',
'sfllaw',
'itkz',
'everes',
'plagger',
'mao999',
'yukkie',
'torikawa',
'metarand',
'mspeicher',
'mjollnir',
'dgcombs',
'harpere',
'twtg',
'y_arim',
'washyu',
'tomita',
'pecheurdeperles'
];
会話が成り立つかも
$VAR1 = [
'll_koba_ll',
'rytich',
'amachang',
'yusukebe',
'tsupo',
'Zoker',
'goricop',
'zakame',
'hakobe',
'issm',
'ikasam_a',
'lapis25',
'takesako',
'umiyosh',
'yksk',
'weboo',
'komatsuna',
'racoon',
'satoship',
'9232',
'masayashi',
'ikko',
'soel',
'himanainu_kawai',
'akio0911',
'moro',
'sekka',
'maedana',
'mzp',
'mazucon',
'tomisima',
'nekoya',
'k12u',
'citrocube',
'hitode909',
'kopug',
'arvined',
'osa',
'jimwalton',
'maybowjing',
'ban_yheld',
'rm233',
'Nick0510',
'kimidora',
'igoigo',
'nuwaa',
'kuy',
'teruyan',
'unclegeorge',
'benopt',
'MyUFO',
'Sixeight',
'm99oore',
'yheld',
'zedomax',
'satou30',
'taisei3200',
'bayside',
'jigenndaisuke',
'21c',
'hirameki',
'mapi',
'kasshy',
'rewish',
'Xyo'
];
http://coderepos.org/share/browser/lang/perl/Net-Twitter-FriendFinder
svn co http://svn.coderepos.org/share/lang/perl/Net-Twitter-FriendFinder/trunk/
Net::Twitter::Friend::Finderのインターフェイスを変更したので、
名前を変えてNet::Twitter::FriendFinderというのを作りました。
use Net::Twitter::FriendFinder; my $tf = Net::Twitter::FriendFinder->new({ setting => {limit => 10 }, from => { Google => { coverage => 4 , lang=> 'ja' }, Twitter => { coverage => 4 , handicap => 1.3 } , } }); $tf->search( 'エロ' ); $tf->show();
あなたのおすすめユーザをパッケージにして配布すれば、手間が省けること間違い無し。
package OreOre::Osusume; use strict; use warnings; use base qw/Net::Twitter::FriendFinder::From/; sub search { # id => score return { tomyhero => 10000, kopug => 1, help => 10, } } 1;
#!/usr/bin/perl use Net::Twitter::FriendFinder; my $tf = Net::Twitter::FriendFinder->new({ from => { '+OreOre::Osusume' => {}, } }); $tf->search(); $tf->show();
グーグルには、サイト縛り検索ができるので、それを利用してユーザを探せば、
興味のあることを発言しているユーザを見つけることができます。
こんな感じですね。
site:.twitter.com [検索したい文字]
http://coderepos.org/share/browser/lang/perl/Net-Twitter-Friend-Finder
svn co http://svn.coderepos.org/share/lang/perl/Net-Twitter-Friend-Finder/trunk/
Net::Twitter::Friend::Finder::FromGoogle というモジュールを作ったので、これを使うとさらに楽です。sample.plというのを同封してますので、それをつかうとさらさらにに楽です。
'Test::More' => 0,
'Web::Scraper' => 0,
'URI' => 0,
'URI::Escape' => 0,
'Net::Twitter' => 0,
'Text::SimpleTable' => 0,
'FindBin::libs' => 0,
'Class::Accessor::Fast' => 0,
'Getopt::Long' => 0,
使用例
perl sample.pl --read_only --keyword=warcraft3 --lang=ja
# read_onlyを取り除き、あなたのTwitter情報を追加 perl sample.pl --keyword=warcraft3 --lang=ja --username=username --password=password
sample.plのデフォルトでは、5ページx100件の中から上位20件を探します。
これは変更もすることができます。(100件は修正できません)
これで、1ページx100件の中から上位5件を探します。注意として、スコアーは、対象ユーザ引っかかった総数で計算しています。つまり、上位に表示されていようが、下位に表示されていようが関係ないです。
perl sample.pl --read_only --keyword=warcraft3 --lang=ja --limit=5 --end_page=1
私のようなシャイなTwitterユーザ方でも、スクリプトを実行すると強制的に見つけた人をfollowします。
ですので、「スクリプト走らせたら、自動でfollowしちゃったよー」的な理由を作ってくて、少し気が楽です。
この条件で実行すると、おそらく私しか引っかからないので、練習にはもってこいです。
perl sample.pl --keyword='tomyhero' --limit=1 --username=username --password=password
以下予定インターフェイス。どうだろうか。ちょっと訂正
use Net::Twitter::FriendFinder; my $tf = Net::Twitter::FriendFinder->new({ setting => { limit => 20, }, default => { coverage => 1, } , from => { Google => { coverage => 4 }, Twitter => { } , } }); $tf->search( $keyword ); $tf->show(); $tf->follow({ username => '****' , password=> '******' });