/[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

Contents of /trunk/sender.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (show annotations)
Sat May 14 12:31:27 2005 UTC (18 years, 10 months ago) by dpavlin
File MIME type: text/plain
File size: 2829 byte(s)
added --queue

1 #!/usr/bin/perl -w
2
3 use strict;
4 use Class::DBI::Loader::Pg;
5 use Getopt::Long;
6 use Data::Dumper;
7
8 =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(
19 "list" => \$list_opt,
20 "add=s" => \$add_opt,
21 "queue=s" => \$queue_opt,
22 "debug" => \$debug,
23 );
24
25
26 my $loader = Class::DBI::Loader::Pg->new(
27 debug => $debug,
28 dsn => "dbi:Pg:dbname=notices",
29 user => "dpavlin",
30 password => "",
31 namespace => "Noticer",
32 # additional_classes => qw/Class::DBI::AbstractSearch/,
33 # additional_base_classes => qw/My::Stuff/,
34 relationships => 1,
35 );
36
37 my $lists = $loader->find_class('lists');
38 my $users = $loader->find_class('users');
39 my $user_list = $loader->find_class('user_list');
40 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) {
45 print $list->name,"\n";
46 foreach my $user_on_list ($user_list->search(list_id => $list->id)) {
47 my $user = $users->retrieve( id => $user_on_list->user_id );
48 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 {
108 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

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26