/[notice-sender]/trunk/sender.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/sender.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Fri May 13 21:17:58 2005 UTC revision 2 by dpavlin, Fri May 13 22:08:44 2005 UTC
# Line 5  use Class::DBI::Loader::Pg; Line 5  use Class::DBI::Loader::Pg;
5  use Getopt::Long;  use Getopt::Long;
6  use Data::Dumper;  use Data::Dumper;
7    
8  my ($lists,$debug) = (0,0);  my ($list_opt,$debug) = (0,0);
9    my $add_opt;
10    
11  my $result = GetOptions(  my $result = GetOptions(
12          "lists" => \$lists,          "list"  => \$list_opt,
13            "add=s" => \$add_opt,
14          "debug" => \$debug,          "debug" => \$debug,
15  );  );
16    
# Line 24  my $loader = Class::DBI::Loader::Pg->new Line 26  my $loader = Class::DBI::Loader::Pg->new
26          relationships   => 1          relationships   => 1
27  );  );
28    
29  if ($lists) {  my $lists = $loader->find_class('lists');
30          my $lists = $loader->find_class('lists');  my $users = $loader->find_class('users');
31          my $users = $loader->find_class('users');  my $user_list = $loader->find_class('user_list');
32          my $user_list = $loader->find_class('user_list');  
33    if ($list_opt) {
34          foreach my $list ($lists->retrieve_all) {          foreach my $list ($lists->retrieve_all) {
35                  print $list->name,"\n";                  print $list->name,"\n";
36                  foreach my $user_on_list ($user_list->search(list_id => $list->id)) {                  foreach my $user_on_list ($user_list->search(list_id => $list->id)) {
# Line 35  if ($lists) { Line 38  if ($lists) {
38                          print "\t",$user->full_name," <", $user->email, ">\n";                          print "\t",$user->full_name," <", $user->email, ">\n";
39                  }                  }
40          }          }
41    } elsif ($add_opt) {
42            #my $noticer = $loader->find_class('Noticer') || die "can't find my class!";
43            foreach my $c_name ($loader->tables) {
44                    my $c = $loader->find_class($c_name)|| die "can't find $c_name";
45                    $c->autoupdate(1);
46            }
47                    
48            my $list = $lists->find_or_create({
49                    name => $add_opt,
50            }) || die "can't add list $add_opt\n";
51            my $added = 0;
52            while(<>) {
53                    chomp;
54                    next if (/^#/ || /^\s*$/);
55                    my ($email, $name) = split(/\s+/,$_, 2);
56                    print "# $name <$email>\n";
57                    my $this_user = $users->find_or_create({
58                            email => $email,
59                            full_name => $name,
60                    }) || die "can't find or create member\n";
61                    my $user_on_list = $user_list->find_or_create({
62                            user_id => $this_user->id,
63                            list_id => $list->id,
64                    }) || die "can't add user to list";
65            }
66            print "processed $added members\n";
67  } else  {  } else  {
68          die "$0: unknown command";          die "$0 --lists --list-add=name_of_list --debug\n";
69  }  }
70    
71    

Legend:
Removed from v.1  
changed lines
  Added in v.2

  ViewVC Help
Powered by ViewVC 1.1.26