Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Couple more list management utilities. Edited create_lists.

  • Loading branch information...
commit 27f90cde5f22817cb9c6014e9bcb74490587c37a 1 parent a7441e8
Dave Cross authored
Showing with 98 additions and 17 deletions.
  1. +24 −17 bin/create_lists
  2. +40 −0 bin/delete_excess_lists
  3. +34 −0 bin/set_list_ids
41 bin/create_lists
View
@@ -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;
@@ -66,6 +74,5 @@ foreach my $con ($con_rs->all) {
list_id => $list->{id},
screen_name => $cand->twitter,
});
- sleep 2;
}
}
40 bin/delete_excess_lists
View
@@ -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 bin/set_list_ids
View
@@ -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;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.