summaryrefslogtreecommitdiff
path: root/twitlist.pl
diff options
context:
space:
mode:
Diffstat (limited to 'twitlist.pl')
-rw-r--r--twitlist.pl23
1 files changed, 15 insertions, 8 deletions
diff --git a/twitlist.pl b/twitlist.pl
index fe049a0..21c3ce5 100644
--- a/twitlist.pl
+++ b/twitlist.pl
@@ -150,14 +150,21 @@ sub parse_friends_lists_matrix {
}
sub make_it_so {
- my ($tw,$current_lists,$wanted_lists) = @_;
+ my ($tw,$current_lists_by_id,$wanted_lists) = @_;
+
+ my %current_lists_by_name = map {
+ $current_lists_by_id->{$_}{name} => {
+ id => $_,
+ $current_lists_by_id->{$_}->%*,
+ };
+ } keys $current_lists_by_id->%*;
my @operations;
# first, lists to create
for my $list (keys $wanted_lists->%*) {
- if ($current_lists->{$list}) {
- $wanted_lists->{$list}{id} ||= $current_lists->{$list}{id};
- if ($wanted_lists->{$list}{id} != $current_lists->{$list}{id}) {
+ if ($current_lists_by_name{$list}) {
+ $wanted_lists->{$list}{id} ||= $current_lists_by_name{$list}{id};
+ if ($wanted_lists->{$list}{id} != $current_lists_by_name{$list}{id}) {
warn "list $list has conflicting ids!\n";
}
}
@@ -170,7 +177,7 @@ sub make_it_so {
else {
$list_data = { id => int(rand(10000)) };
}
- $current_lists->{$list} = {
+ $current_lists_by_name{$list} = {
$list_data->%{id},
members => {},
};
@@ -179,7 +186,7 @@ sub make_it_so {
# then, set members
for my $list (keys $wanted_lists->%*) {
warn "operating on $list\n";
- my %current_members = $current_lists->{$list}->{members}->%*;
+ my %current_members = $current_lists_by_name{$list}->{members}->%*;
my %wanted_members = $wanted_lists->{$list}{members}->%*;
my %to_add = %wanted_members; delete @to_add{keys %current_members};
my %to_remove = %current_members; delete @to_remove{keys %wanted_members};
@@ -188,7 +195,7 @@ sub make_it_so {
warn "Removing @these from $list\n";
if ($WRITING) {
$tw->remove_list_members({
- list_id => $current_lists->{$list}{id},
+ list_id => $current_lists_by_name{$list}{id},
user_id => \@these,
});
}
@@ -198,7 +205,7 @@ sub make_it_so {
warn "Adding @these to $list\n";
if ($WRITING) {
$tw->add_list_members({
- list_id => $current_lists->{$list}{id},
+ list_id => $current_lists_by_name{$list}{id},
user_id => \@these,
});
}