Skip to content

Commit

Permalink
Couple more list management utilities. Edited create_lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Aug 22, 2014
1 parent a7441e8 commit 27f90cd
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 17 deletions.
41 changes: 24 additions & 17 deletions bin/create_lists
Expand Up @@ -37,27 +37,35 @@ $t->authorise;
foreach my $con ($con_rs->all) {
next unless $con->candidates->count;
say $con->name;


my $list;
eval {
if ($con->list_id) {
say 'Delete ', $con->list_name;
$t->delete_list({
list_id => $con->list_id,
$list = $t->show_list({
owner_screen_name => 'twittelection',
list_id => $con->list_id,
});
if ($list) {
foreach my $mem (@{$t->list_members({ list_id => $list->{id} })->{users}}) {
$t->remove_list_members({
list_id => $list->{id},
screen_name => $mem->{screen_name},
});
}
}
} else {
say 'Create ', $con->name;
$list = $t->create_list({
owner_screen_name => 'twittelection',
name => $con->name,
});

$con->update({
list_name => $list->{slug},
list_id => $list->{id},
});
}
};
say 'Create ', $con->name;
my $list = $t->create_list({
owner_screen_name => 'twittelection',
name => $con->name,
});
say "Created $list->{slug} ($list->{id})";
sleep 2;

$con->update({
list_name => $list->{slug},
list_id => $list->{id},
});

foreach my $cand ($con->candidates) {
next unless $cand->twitter;
Expand All @@ -66,6 +74,5 @@ foreach my $con ($con_rs->all) {
list_id => $list->{id},
screen_name => $cand->twitter,
});
sleep 2;
}
}
40 changes: 40 additions & 0 deletions bin/delete_excess_lists
@@ -0,0 +1,40 @@
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;
use lib 'lib';

use TwittElection::Schema;
use TwittElection::Twitter;

my $sch = TwittElection::Schema->connect(
"dbi:mysql:database=$ENV{TE_DB}", $ENV{TE_USER}, $ENV{TE_PASS},
{ mysql_enable_utf8 => 1 },
) or die;

my $const_rs = $sch->resultset('Constituency');

my $t = TwittElection::Twitter->new(
traits => [ 'API::RESTv1_1', 'OAuth' ],
ssl => 1,
consumer_key => $ENV{TE_TW_API_KEY},
consumer_secret => $ENV{TE_TW_API_SEC},
);

$t->authorise;

foreach my $list (@{$t->list_ownerships->{lists}}) {
say $list->{name}, ' (', $list->{id}, ')';
my $const = $const_rs->find({
list_id => $list->{id},
list_name => $list->{name},
});

next if $const;

say "Deleting...";
$t->delete_list({
list_id => $list->{id},
});
}
34 changes: 34 additions & 0 deletions bin/set_list_ids
@@ -0,0 +1,34 @@
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;
use lib 'lib';

use TwittElection::Schema;
use TwittElection::Twitter;

my $sch = TwittElection::Schema->connect(
"dbi:mysql:database=$ENV{TE_DB}", $ENV{TE_USER}, $ENV{TE_PASS},
{ mysql_enable_utf8 => 1 },
) or die;

my $const_rs = $sch->resultset('Constituency');

my $t = TwittElection::Twitter->new(
traits => [ 'API::RESTv1_1', 'OAuth' ],
ssl => 1,
consumer_key => $ENV{TE_TW_API_KEY},
consumer_secret => $ENV{TE_TW_API_SEC},
);

$t->authorise;

foreach my $list (@{$t->list_ownerships->{lists}}) {
say $list->{name}, ' (', $list->{id}, ')';
my $const = $const_rs->find({
list_name => $list->{name},
});

$const->update({ list_id => $list->{id} }) if $const;
}

0 comments on commit 27f90cd

Please sign in to comment.