/[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 6 by dpavlin, Sat May 14 12:31:27 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);  =head1 NAME
9    
10    sender.pl - command line notify sender utility
11    
12    =cut
13    
14    my ($list_opt,$debug) = (0,0);
15    my $add_opt;
16    my $queue_opt;
17    
18  my $result = GetOptions(  my $result = GetOptions(
19          "lists" => \$lists,          "list"  => \$list_opt,
20            "add=s" => \$add_opt,
21            "queue=s" => \$queue_opt,
22          "debug" => \$debug,          "debug" => \$debug,
23  );  );
24    
# Line 21  my $loader = Class::DBI::Loader::Pg->new Line 31  my $loader = Class::DBI::Loader::Pg->new
31          namespace       => "Noticer",          namespace       => "Noticer",
32  #       additional_classes      => qw/Class::DBI::AbstractSearch/,  #       additional_classes      => qw/Class::DBI::AbstractSearch/,
33  #       additional_base_classes => qw/My::Stuff/,  #       additional_base_classes => qw/My::Stuff/,
34          relationships   => 1          relationships   => 1,
35  );  );
36    
37  if ($lists) {  my $lists = $loader->find_class('lists');
38          my $lists = $loader->find_class('lists');  my $users = $loader->find_class('users');
39          my $users = $loader->find_class('users');  my $user_list = $loader->find_class('user_list');
40          my $user_list = $loader->find_class('user_list');  my $messages = $loader->find_class('messages');
41    my $message_list = $loader->find_class('message_list');
42    
43    if ($list_opt) {
44          foreach my $list ($lists->retrieve_all) {          foreach my $list ($lists->retrieve_all) {
45                  print $list->name,"\n";                  print $list->name,"\n";
46                  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 48  if ($lists) {
48                          print "\t",$user->full_name," <", $user->email, ">\n";                          print "\t",$user->full_name," <", $user->email, ">\n";
49                  }                  }
50          }          }
51    } elsif ($add_opt) {
52            #my $noticer = $loader->find_class('Noticer') || die "can't find my class!";
53            my $list = $lists->find_or_create({
54                    name => $add_opt,
55            }) || die "can't add list $add_opt\n";
56    
57            my $added = 0;
58    
59            while(<>) {
60                    chomp;
61                    next if (/^#/ || /^\s*$/);
62                    my ($email, $name) = split(/\s+/,$_, 2);
63                    print "# $name <$email>\n";
64                    my $this_user = $users->find_or_create({
65                            email => $email,
66                            full_name => $name,
67                    }) || die "can't find or create member\n";
68                    my $user_on_list = $user_list->find_or_create({
69                            user_id => $this_user->id,
70                            list_id => $list->id,
71                    }) || die "can't add user to list";
72                    $added++;
73            }
74    
75            foreach my $c_name ($loader->tables) {
76                    my $c = $loader->find_class($c_name)|| die "can't find $c_name";
77                    $c->dbi_commit();
78            }
79    
80            print "list ",$list->name," has $added users\n";
81    
82    } elsif ($queue_opt) {
83            my $this_list = $lists->search(
84                    name => $queue_opt,
85            )->first || die "can't find list $queue_opt";
86    
87            my $message_text;
88            while(<>) {
89                    $message_text .= $_;
90            }
91    
92            die "no message" unless ($message_text);
93    
94            my $this_message = $messages->find_or_create({
95                    message => $message_text
96            }) || die "can't insert message";
97    
98            $this_message->dbi_commit();
99    
100            $message_list->find_or_create({
101                    message_id => $this_message->id,
102                    list_id => $this_list->id,
103            }) || die "can't add message ",$this_message->id," to list ",$this_list->id, ": ",$this_list->name;
104    
105            print "added message ",$this_message->id, " to list ",$this_list->name,"\n";
106    
107  } else  {  } else  {
108          die "$0: unknown command";          die $0.'
109            --list                          show all lists and users
110            --add=name_of_list < users.txt  add users (email@example.com full name)
111            --queue=name_of_list < message  queue message for sending to list
112            --debug
113    ';
114  }  }
115    
   

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

  ViewVC Help
Powered by ViewVC 1.1.26