From 8f15143fcef937f3085f3fe5dc7be4d896fa384c Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 19 Dec 2015 13:09:46 +0000 Subject: input works --- twitlist.pl | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'twitlist.pl') 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, }); } -- cgit v1.2.3