Show
Ignore:
Timestamp:
11/18/07 07:35:24 (7 years ago)
Author:
xcezx
Message:

/dotfiles/irssi/xcezx-config: 最近の。

  • lang/parl/irssi/scripts/delicious.pl: Finds URLs and posts them to del.icio.us on irssi
Location:
lang/perl/Net-Twitter-Diff/tags
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Net-Twitter-Diff/tags/0.03/Makefile.PL

    r1446 r1737  
    1212        'Test::More'      => 0, 
    1313        'Net::Twitter'    => 0, 
     14        'Class::Accessor' => 0, 
    1415        'Array::Diff'     => 0, 
    1516    }, 
  • lang/perl/Net-Twitter-Diff/tags/0.03/lib/Net/Twitter/Diff.pm

    r1446 r1737  
    242242=head1 AUTHOR 
    243243 
    244 Tomohiro Teranishi<tomohiro.teranishi@gmail.com. 
     244Tomohiro Teranishi<tomohiro.teranishi@gmail.com> 
    245245 
    246246=cut 
  • lang/perl/Net-Twitter-Diff/tags/0.04/Changes

    r1577 r1737  
    11Revision history for Net-Twitter-Diff 
    2  
    3 0.04    2007-11-15/16:25 
    4         - Fix POD 
    5  
    6 0.03    2007-11-14/11:04 
    7         - Relase on CPAN 
    8  
    9 0.02    2007-11-14/00:05 
    10         - Change Interface. 
    11         - Support comp_following ,xfollowing , xfollowers 
    122 
    1330.01    2007-11-08/21:27 
  • lang/perl/Net-Twitter-Diff/tags/0.04/META.yml

    r1577 r1737  
    1 # http://module-build.sourceforge.net/META-spec.html 
    2 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX# 
    3 name:         Net-Twitter-Diff 
    4 version:      0.04 
    5 version_from: lib/Net/Twitter/Diff.pm 
    6 installdirs:  site 
    7 requires: 
    8     Array::Diff:                   0 
    9     Net::Twitter:                  0 
    10     Test::More:                    0 
    11  
    12 distribution_type: module 
    13 generated_by: ExtUtils::MakeMaker version 6.30 
  • lang/perl/Net-Twitter-Diff/tags/0.04/Makefile.PL

    r1446 r1737  
    1212        'Test::More'      => 0, 
    1313        'Net::Twitter'    => 0, 
     14        'Class::Accessor' => 0, 
    1415        'Array::Diff'     => 0, 
    1516    }, 
  • lang/perl/Net-Twitter-Diff/tags/0.04/lib/Net/Twitter/Diff.pm

    r1577 r1737  
    33use warnings; 
    44use strict; 
    5 use base qw/Net::Twitter/; 
     5use Net::Twitter; 
     6use base qw/Class::Accessor/; 
    67use Array::Diff; 
    78 
    8 our $VERSION = '0.04'; 
     9__PACKAGE__->mk_accessors(qw/not_following not_followed communicated/); 
    910 
    10 sub xfollowing { 
    11     my $self = shift; 
    12     my $id   = shift; 
     11our $VERSION = '0.01'; 
    1312 
    14       my $url = $self->{apiurl} . "/statuses/friends" ; 
    15       $url .= (defined $id) ? "/$id.json" : ".json"; 
    16       $url .= '?page='; 
    17      
    18     my $page = 1; 
    19     my @data = (); 
    20     while(1){ 
    21         my $page_url = $url . $page ; 
    22         my $req = $self->{ua}->get($page_url); 
     13sub Net::Twitter::following_screen_names { 
     14    my ( $self ) = @_; 
    2315 
    24         die 'fail to connect to twitter. maybe over Rate limit exceeded or auth error' unless $req->is_success; 
    25         return [] if $req->content eq 'null'; 
    26  
    27         my $res = JSON::Any->jsonToObj($req->content) ; 
    28  
    29         last unless scalar @{ $res } ; 
    30         push @data , @{ $res } ; 
    31  
    32  
    33         $page++; 
    34     } 
    35  
    36     return \@data; 
    37 } 
    38  
    39 sub xfollowers { 
    40     my $self = shift; 
    41      
    42     my $page = 1; 
    43     my @data = (); 
    44     while(1){ 
    45         my $url = $self->{apiurl} . "/statuses/followers.json?page=$page" ; 
     16    my @screen_names = (); 
     17    # limit 20 pages for now.( 2000 twitters ) 
     18    my @pages = (1..20); 
     19    for my $page ( @pages ) { 
     20        my $url = $self->{apiurl} . "/statuses/friends.json?page=$page" ; 
    4621        my $req = $self->{ua}->get($url); 
    4722 
     
    5227 
    5328        last unless scalar @{ $res } ; 
    54         push @data , @{ $res } ; 
     29 
     30        for my $item ( @{ $res } ) { 
     31            push @screen_names , $item->{screen_name}; 
     32        } 
     33    } 
     34 
     35    return \@screen_names; 
     36} 
    5537 
    5638 
    57         $page++; 
    58     } 
    59  
    60     return \@data; 
    61 } 
    6239 
    6340sub diff { 
     
    6542    my $args = shift; 
    6643 
    67     my $res = {}; 
    68     my $followings_hash = $self->xfollowing(); 
    69     my $followers_hash   = $self->xfollowers(); 
     44    my $twitter = Net::Twitter->new( username => $args->{username} , password => $args->{password} ) ; 
     45 
     46    my $followings = $twitter->following_screen_names(); 
     47    my $followers_hash   = $twitter->followers(); 
    7048    my $followers = []; 
    71     my $followings = []; 
    72  
    73     for my $item ( @{ $followings_hash } ) { 
    74         push @{ $followings } , $item->{screen_name}; 
    75     } 
    7649 
    7750    for my $item ( @{ $followers_hash } ) { 
     
    8154    my $diff = Array::Diff->diff( $followers , $followings ); 
    8255 
    83     $res->{not_following} = $diff->deleted;  
    84     $res->{not_followed}  = $diff->added;  
     56    $self->{not_following} = $diff->deleted;  
     57    $self->{not_followed}  = $diff->added;  
    8558    my @communicated = (); 
    8659    my $not_followed_ref = {}; 
    87     for my $user ( @{  $res->{not_followed} } ) { 
     60    for my $user ( @{  $self->{not_followed} } ) { 
    8861           $not_followed_ref->{ $user } = 1;  
    8962    } 
     
    9568    } 
    9669 
    97     $res->{communicated} = \@communicated; 
    98  
    99     return $res; 
    100 } 
    101  
    102  
    103 sub comp_following { 
    104     my $self = shift; 
    105     my $id   = shift; 
    106  
    107     my $res = {}; 
    108     my $me_ref = $self->xfollowing(); 
    109     my $him_ref = $self->xfollowing( $id ); 
    110  
    111      
    112     my $me  = []; 
    113     my $him = []; 
    114     my $me_hash = {}; 
    115     for my $item ( @{ $me_ref } ) { 
    116         push @{ $me } , $item->{screen_name}; 
    117         $me_hash->{ $item->{screen_name} } = 1; 
    118     } 
    119  
    120     for my $item ( @{ $him_ref } ) { 
    121         push @{ $him } , $item->{screen_name}; 
    122     } 
    123  
    124     my $diff = Array::Diff->diff( $me , $him ); 
    125  
    126     $res->{only_me} = $diff->deleted;  
    127     $res->{not_me}  = $diff->added;  
    128     my @communicated = (); 
    129  
    130     for my $screen_name ( @{ $him } ) { 
    131         if ( defined $me_hash->{ $screen_name  } ) { 
    132             push @communicated , $screen_name  
    133         } 
    134     } 
    135  
    136     $res->{share} = \@communicated; 
    137  
    138     return $res; 
     70    $self->{communicated} = \@communicated; 
    13971} 
    14072 
     
    14981    use Net::Twitter::Diff; 
    15082 
    151     my $diff = Net::Twitter::Diff->new(  username => '******' , password => '******'); 
     83    my $diff = Net::Twitter::Diff->new(); 
    15284     
    153     my $res = $diff->diff(); 
     85    $diff->diff( { username => '******' , password => '******' } ); 
    15486 
    15587    # get screen_names who you are not following but they are. 
    156     print Dumper $res->{not_following}; 
     88    print Dumper $diff->not_following(); 
    15789 
    15890    # get screen_names who they are not following but you are. 
    159     print Dumper $res->{not_followed}; 
     91    print Dumper $diff->not_followed(); 
    16092 
    16193    # get screen_names who you are following them and also they follow you.  
    162     print Dumper $res->{communicated};  
     94    print Dumper $diff->communicated();  
    16395 
    164  
    165     my $res2 = $diff->comp_following( 'somebody_twitter_name' ); 
    166  
    167     # only you are following 
    168     print Dumper $res2->{only_me} ; 
    169  
    170     # you are not following but somebody_twitter_name are following 
    171     print Dumper $res2->{not_me} ; 
    172  
    173     # both you and somebody_twitter_name are following 
    174     print Dumper $res2->{share} ; 
    175  
    176  
    177     # If you want , this module use Net::Twitter as base so you can use methods Net::Twitter has. 
    178     $diff->update('My current Status'); 
    179      
    18096=head1 DESCRIPTION 
    18197 
    182 Handy when you want to know relationshop between your followers and follwoings 
    183 and when you wnat to compare your following and somebody's. 
     98Just handy when you want know relationshop between your followers and follwoings. 
    18499 
    185100=head1 METHOD 
    186101 
    187 =head2 diff 
     102=head2 diff({username=>$username ,password => $password}) 
    188103 
    189104run diff 
    190105 
    191 response hash 
    192  
    193 =over 4 
    194  
    195 =item B<not_following> 
     106=head2 not_following 
    196107 
    197108get screen_names who you are not following but they are. 
    198109 
    199 =item B<not_followed> 
     110=head2 not_followed 
    200111 
    201112get screen_names who they are not following but you are. 
    202113 
    203 =item B<communicated> 
     114=head2 communicated 
    204115 
    205116get screen_names who you are following them and also they follow you.  
    206117 
    207 =back 
    208  
    209 =head2 comp_following( $twitter_id ) 
    210  
    211 compaire your following and somebody's 
    212  
    213 response hash 
    214  
    215 =over 4 
    216  
    217 =item B<only_me> 
    218  
    219 only you are following 
    220  
    221 =item B<not_me> 
    222  
    223 you are not following but somebody is following 
    224  
    225 =item B<share> 
    226  
    227 both you and somebody are following. 
    228  
    229 =back 
    230  
    231 =head2 xfollowing 
    232  
    233 can get more that 100 followings. 
    234  
    235 =head2 xfollowers 
    236  
    237 can get more that 100 followers. 
    238  
    239 =head1 SEE ALSO 
    240  
    241 L<Net::Twitter> 
    242  
    243118=head1 AUTHOR 
    244119 
    245 Tomohiro Teranishi<tomohiro.teranishi@gmail.com> 
     120Tomohiro Teranishi<tomohiro.teranishi@gmail.com. 
    246121 
    247122=cut