--- trunk/sender.pl 2005/05/13 21:17:58 1 +++ trunk/sender.pl 2005/05/13 22:08:44 2 @@ -5,10 +5,12 @@ use Getopt::Long; use Data::Dumper; -my ($lists,$debug) = (0,0); +my ($list_opt,$debug) = (0,0); +my $add_opt; my $result = GetOptions( - "lists" => \$lists, + "list" => \$list_opt, + "add=s" => \$add_opt, "debug" => \$debug, ); @@ -24,10 +26,11 @@ relationships => 1 ); -if ($lists) { - my $lists = $loader->find_class('lists'); - my $users = $loader->find_class('users'); - my $user_list = $loader->find_class('user_list'); +my $lists = $loader->find_class('lists'); +my $users = $loader->find_class('users'); +my $user_list = $loader->find_class('user_list'); + +if ($list_opt) { foreach my $list ($lists->retrieve_all) { print $list->name,"\n"; foreach my $user_on_list ($user_list->search(list_id => $list->id)) { @@ -35,8 +38,34 @@ print "\t",$user->full_name," <", $user->email, ">\n"; } } +} elsif ($add_opt) { + #my $noticer = $loader->find_class('Noticer') || die "can't find my class!"; + foreach my $c_name ($loader->tables) { + my $c = $loader->find_class($c_name)|| die "can't find $c_name"; + $c->autoupdate(1); + } + + my $list = $lists->find_or_create({ + name => $add_opt, + }) || die "can't add list $add_opt\n"; + my $added = 0; + while(<>) { + chomp; + next if (/^#/ || /^\s*$/); + my ($email, $name) = split(/\s+/,$_, 2); + print "# $name <$email>\n"; + my $this_user = $users->find_or_create({ + email => $email, + full_name => $name, + }) || die "can't find or create member\n"; + my $user_on_list = $user_list->find_or_create({ + user_id => $this_user->id, + list_id => $list->id, + }) || die "can't add user to list"; + } + print "processed $added members\n"; } else { - die "$0: unknown command"; + die "$0 --lists --list-add=name_of_list --debug\n"; }