use warnings; use strict; use Net::Twitter::Lite; use Data::Dumper; use lib '../../files/perl/lib'; use Base::Roots qw(get_data); use Base::Nifty qw(filify); my $directory = 'personal/Twitter'; my $file_die = "Can't open the file"; my $twit_id = "Lady_Aleena"; my $nt = Net::Twitter::Lite->new( consumer_key => 'in the code', consumer_secret => 'in the code', access_token => 'in the code', access_token_secret => 'in the code', ); # Not all data I want is on Twitter, some of these lists are not created, # but I want to create them in the third script. my %twitter_lists = ( 'Andromeda' => { 'network' => 'unknown', }, 'Babylon 5' => { 'network' => 'unknown', }, 'Body of Proof' => { 'network' => 'ABC', }, 'Bones' => { 'network' => 'FOX', }, 'Buffy and Angel' => { 'network' => 'unknown', }, 'Burn Notice' => { 'network' => 'USA', }, 'Castle' => { 'network' => 'ABC', }, 'Chuck' => { 'network' => 'NBC', }, 'Covert Affairs' => { 'network' => 'USA', }, 'Doctor Who' => { 'network' => 'BBC', }, 'ER' => { 'network' => 'NBC', }, 'Eureka Warehouse13 Alphas' => { 'network' => 'Syfy', }, 'Firefly' => { 'network' => 'unknown', }, 'Haven' => { 'network' => 'Syfy', }, 'Law & Order' => { 'network' => 'NBC', }, 'Leverage' => { 'network' => 'TNT', }, 'Necessary Roughness' => { 'network' => 'USA', }, 'No Ordinary Family' => { 'network' => 'ABC' }, 'Rizzoli & Isles' => { 'network' => 'TNT', }, 'Sanctuary' => { 'network' => 'Syfy', }, 'seaQuest' => { 'network' => 'NBC', }, 'Stargate' => { 'network' => 'Syfy', }, 'Star Trek' => { 'network' => 'unknown', }, 'Studio 60' => { 'network' => 'NBC', }, 'White Collar' => { 'network' => 'USA', }, 'The X-Files & Millennium' => { 'network' => 'FOX', }, ); # my @raw_lists; for ( my $cursor = -1; $cursor; ) { my $r = $nt->get_lists({ user => $twit_id, cursor => $cursor }); push @raw_lists, @{$r->{lists}}; $cursor = $r->{next_cursor}; } my @lists; for my $list (@raw_lists) { my $name = $list->{'name'}; $twitter_lists{$name}{'name'} = $name; $twitter_lists{$name}{'slug'} = $list->{'slug'}; $twitter_lists{$name}{'id'} = $list->{'id'}; $twitter_lists{$name}{'mode'} = $list->{'mode'}; $twitter_lists{$name}{'description'} = $list->{'description'}; push @lists, $list->{'slug'}; } my %raw_lists_follows; for my $list (@lists) { for ( my $cursor = -1; $cursor; ) { my $r = $nt->list_members($twit_id, $list, { cursor => $cursor }); push @{$raw_lists_follows{$list}{following}}, @{$r->{users}}; $cursor = $r->{next_cursor}; } for ( my $cursor = -1; $cursor; ) { my $r = $nt->list_subscribers($twit_id, $list, { cursor => $cursor }); push @{$raw_lists_follows{$list}{followers}}, @{$r->{users}}; $cursor = $r->{next_cursor}; } } sub get_list_name { my ($slug) = @_; for my $twitter_list (keys %twitter_lists) { if ($twitter_lists{$twitter_list}{slug} eq $slug) { return $twitter_list; } } } for my $raw_list (keys %raw_lists_follows) { my $list = get_list_name($raw_list); for my $following (@{$raw_lists_follows{$raw_list}{following}}) { my $name = $following->{'name'}; $twitter_lists{$list}{following}{$name}{'name'} = $name; $twitter_lists{$list}{following}{$name}{'screen_name'} = $following->{'screen_name'}; $twitter_lists{$list}{following}{$name}{'id'} = $following->{'id'}; } for my $followers (@{$raw_lists_follows{$raw_list}{followers}}) { my $name = $followers->{'name'}; $twitter_lists{$list}{followers}{$name}{'name'} = $name; $twitter_lists{$list}{followers}{$name}{'screen_name'} = $followers->{'screen_name'}; $twitter_lists{$list}{followers}{$name}{'id'} = $followers->{'id'}; } } my @twitter_list_file_lines; for $twitter_list (sort keys %twitter_lists) { my $list_name = $twitter_lists{$twitter_list}{name}; my $list_slug = $twitter_lists{$twitter_list}{slug}; my $list_id = $twitter_lists{$twitter_list}{id}; my $list_description = $twitter_lists{$twitter_list}{description}; my $list_network = $twitter_lists{$twitter_list}{network}; push @twitter_list_file_lines, qq($list_name|$list_slug|$list_id|$list_description|$list_network); for my $follow ('following','followers') { $directory .= "lists/".filify($list_name); my $people_list_file_name = filify(qq($list_name/$follow.txt)); my @person_list_lines = (); for my $person (sort keys %{$twitter_lists{$twitter_list}{$follow}}) { my $follow_name = $twitter_lists{$twitter_list}{$follow}{$person}{name}; my $follow_screen_name = $twitter_lists{$twitter_list}{$follow}{$person}{screen_name}; my $follow_id = $twitter_lists{$twitter_list}{$follow}{$person}{id}; push @person_list_lines, qq($follow_name|$follow_screen_name|$follow_id); } open(my $people_list_file, '>', get_data($directory,$people_list_file_name) or die "$file_die $people_file"; print $people_list_file join("\n",@person_list_lines); } } open(my $twitter_list_file, '>', get_data($directory,"twitter_lists.txt") or die $file_die; print $twitter_list_file join("\n",@twitter_list_file_lines); #### use warnings; use strict; use Net::Twitter::Lite; use lib '../../files/perl/lib'; use Base::Roots qw(get_data); use Base::Nifty qw(get_hash filify); my $directory = 'personal/Twitter'; my $file_die = "Can't open the file"; my %twitter_lists; my %twitter_lists_data = ( file => qq($directory/twitter_lists.txt), headings => [qw(name slug id description network)], ); get_hash(\%twitter_lists,\%twitter_lists_data); my %networks; for my $list (sort keys %twitter_lists) { my $network = $twitter_lists{$twitter_list}{network}; push @{$networks{$network}}, $list; } for my $network (sort keys %networks) { if ($network !~ /unknown/ or scalar(@{$networks{$network}}) > 1) { my $twit_id = "LadyAleena$network"; my $nt = Net::Twitter::Lite->new( consumer_key => 'in the code', consumer_secret => 'in the code', access_token => , # I need to write the script to get this. access_token_secret => , # I need to write the script to get this. ); for my $show (sort @{$networks{$network}}) { my $directory .= "lists/".filify($list_name); my $slug = $twitter_lists{$show}{slug}; my $r = $nt->create_list({user => $twit_id, name => $show}); my %following_list; my %following_list_data = ( file => qq($directory/following.txt), headings => [qw(name screen_name id)], ); get_hash(\%following_list,%following_list_data); for my $follow (sort keys %following_list) { my $screen_name = $following_list{$follow}{screen_name}; my $r = $nt->add_list_member({user => $twit_id, list_id => $slug, id => $screen_name}); } } } }