Skip to content

Instantly share code, notes, and snippets.

@sburlot
Created March 17, 2011 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sburlot/873961 to your computer and use it in GitHub Desktop.
Save sburlot/873961 to your computer and use it in GitHub Desktop.
Add a list of users to a twitter list
#!/usr/bin/perl
use Net::Twitter;
use Data::Dumper;
$owner = "sburlot"; # <= you should put your name here
$list_name = "NSConf 2011"; # <= name of the twitter list
# put your own values below:
$consumer_key = "";
$consumer_secret = "";
$token = "";
$token_secret = "";
# end of user-serviceable part
# The awesome list
@attendees = qw/aral bmf mattgemmell danielpunkass justinw jakobdamjensen arepty cSquirrel simonmaddox Cgodefroy kevinhoctor ElGrowZone littleknown stefanfuerst martinhering creednmd tenjinuk seanronan smorr catlan plo sgaw adurdin pieteromvlee jordanbreeding CocoaSamurai CodingMammoth refnum danielctull samdeane gloubibou head_min Dative spencerpieters bulusoy tarasis timisted macdevnet richardbuckle iamleeg thegummer neilinglis markuspalmanto cocoafu ErikAderstedt chwalters casademora daveaddey widgetpress uliwitness drewmccormack catshive mzarra jonathandann djembe dwiskus acvivo jivadevoe protocool marksands nst021 Mark_Brindle apparentsoft HexagonalApps kodz meils mrbananas tmaes 0xced dearprakash mobilerelations smeger dannygreg mbogh nikf kch uemit StuFFmc christian_beer ibourke opsGordon yogi_kenobi lucvandal kirbyt friedEggTechnik alastairh iRightRaj wookiee duhanebel gizzard benko rsebbe Uffekoch pbur matteorattotti RossT tbalthazar sburlot roddi _karsten_ bertrand_cachet JSN00K EdWarrick7 phorpin martingoode glebd gmortime robertwijas demianturner judykitteh keith_duncan pardel alancfrancis massivevector th_in_gs battig daveverwer osteslag hatfinch LyonJTill Sbclx DamianOS3/;
# get the lists owned by $owner
# didn't find a way to directly get the ID of a list
sub get_lists {
my $lists = $nt->get_lists($owner);
for ( my $cursor = -1, my $r; $cursor; $cursor = $r->{next_cursor} ) {
$r = $nt->get_lists({ cursor => $cursor, user => $owner });
@lists = @{$r->{lists}};
for $list (@lists) {
my $name = $list->{'name'};
my $id = $list->{'id'};
print "name : $name => $id" . "\n";
if ($name eq $list_name) {
return $id;
}
}
}
return -1;
}
# add awesome people to the list
sub add_users($) {
$list_id = shift @_;
do {
@slice = splice(@attendees, 0, 50);
print "Adding:" . join(',', @slice) . "\n";
$users = $nt->members_create_all($owner, $list_id, { screen_name => \@slice });
$count = scalar(@attendees);
} while ($count > 0);
}
$nt = Net::Twitter->new(
traits => [qw/OAuth API::REST API::Lists/],
consumer_key => $consumer_key,
consumer_secret => $consumer_secret,
access_token => $token,
access_token_secret => $token_secret,
);
# try to find the ID of the list $list_name
$id = get_lists;
if ($id != -1) {
print "Found: $id\n";
add_users($id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment