Skip to content

Instantly share code, notes, and snippets.

@semifor
Created November 29, 2011 22:17
Show Gist options
  • Save semifor/1406831 to your computer and use it in GitHub Desktop.
Save semifor/1406831 to your computer and use it in GitHub Desktop.
Lady_Aleena's account setup script
#!/usr/bin/perl
use warnings;
use strict;
use Net::Twitter::Lite;
use lib '../../files/perl/lib';
use Base::Roots qw(get_data);
my %consumer_tokens = (
consumer_key => 'in script',
consumer_secret => 'in script',
);
my %accounts = qw(
LadyAleena_ABC => {
friends => [qw(ABC AFVofficial BodyOfProofABC Castle_ABC extremehome NoOrdFamilyABC OnceABC)],
lists => [qw(castle)],
},
LadyAleena_FOX => {
friends => [qw(FOXBroadcasting BONESonFOX)],
lists => [qw(bones firefly)],
},
LadyAleena_NBC => {
friends => [qw(nbc nbcchuck NBCFreeAgents NBCGrimm NBCHarrysLaw heroes nbclawandorder nbcsvu USA_LawOrderCi NBCLOLA)],
lists => ['er', 'law-order', 'seaquest', 'studio-60', 'chuck'],
},
LadyAleena_SyFy => {
friends => [qw(Syfy SyfyMovies)],
lists => ['sanctuary', 'haven', 'stargate', 'eureka-warehouse13-alphas'],
},
LadyAleena_TNT => {
friends => [qw(tntweknowdrama FallingSkiesTNT leverageTNT RizzoliIslesTNT)],
lists => ['rizzoli-isles', 'leverage'],
},
LadyAleena_USA => {
friends => [qw(USA_Network BurnNotice_USA CovertAffairs FairlyLegal NecRoughness Suits_USA WhiteCollarUSA)],
lists => ['covert-affairs', 'white-collar', 'burn-notice'],
},
);
my @tokens;
while ( keys %accounts ) {
printf "Accounts remaining to set up: %s\n", join ', ' => keys %accounts;
# Consider using $nt->get_authentication_url, instead, which will allow you to sign out
# of an existing account and sign in with different credentials.
my $auth_url = $nt->get_authorization_url;
print "Log into an account then visit $auth_url, and enter the PIN provided to continue:";
my $pin = <STDIN>; # wait for input
chomp $pin;
my @access_tokens = $nt->request_access_token(verifier => $pin);
my $account = $access_tokens[3];
next unless exists $accounts{$account};
push @tokens, join('|',@access_tokens);
my $channel = $account;
$channel =~ s/LadyAleena_//;
$nt->update_profile({
url => 'http://www.xecu.net/fantasy',
description => "This is \@Lady_Aleena's $channel channel account where she keeps lists of people in $channel's series.",
});
print "$account's profile updated.\n";
$nt->update_profile_background_image({
image => '../../files/images/avatar.jpg',
use => 0,
});
print "$account's background updated.\n";
$nt->update_profile_colors({
profile_background_color => '#000000',
profile_text_color => '#000000',
profile_link_color => '#990033',
profile_sidebar_fill_color => '#ffcc00',
profile_sidebar_border_color => '#990033',
});
print "$account's profile colors updated.\n";
$nt->update_profile_image({
image => '../../files/images/avatar.jpg',
});
print "$account's profile image updated.\n";
$nt->update({ status => "Hello Twitter fans of my favorite $channel TV series!" });
for $friend (@{$accounts{$account}{friends}}) {
$nt->create_friend({
screen_name => $friend,
follow => 'true',
});
$nt->update_friendship({
screen_name => $friend,
retweets => 'false',
});
print "$account is now following $friend.\n";
}
for $list (sort @{{$accounts}{$account}{lists}}) {
my $base_list = $nt->get_list("Lady_Aleena",$list);
my $show = $base_list->{name};
my $show_tag = "\#$show";
$show_tag = s/ //g;
$show_tag = s/&/and/g;
$nt->create_list({
user => $account,
name => $show,
mode =>$base_list->{mode},
description =>$base_list->{description},
});
my $list_status = "\@$account/$list has been created to follow the people of $show! $show_tag";
print "$list_status\n";
$nt->update({ status => $list_status });
my $members = $nt->list_members("Lady_Aleena",$show);
for my $member (@{$members->{users}}) {
my $screen_name = $member->{screen_name};
$nt->add_list_member({
user => $account,
list_id => $list,
id => $screen_name,
});
my $user_add_status = "I just added $screen_name to my $show_tag list \@$account/$list. Welcome!";
print "$user_add_status\n";
$nt->update({ status => $user_add_status });
}
my $subscribers = $nt->list_subscribers("Lady_Aleena",$show);
for my $subscriber (@{$subscribers->{screen_name}}) {
my $subscriber_update = "\@$subscriber: My $show list has moved from \@Lady_Aleena/$list to \@$account/$list.";
print "$subscriber_update\n";
$nt->update({ status => $subscriber_update });
}
}
print "$account is now set up.\n";
delete $accounts{$account};
}
open(my $access_file,'>',get_data('personal/Twitter','tokens.txt')) or die "Can't open tokens.txt. $!";
print $access_file join("\n",@tokens);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment