5 |
use Getopt::Long; |
use Getopt::Long; |
6 |
use Data::Dumper; |
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); |
my ($list_opt,$debug) = (0,0); |
15 |
my $add_opt; |
my $add_opt; |
16 |
|
my $queue_opt; |
17 |
|
|
18 |
my $result = GetOptions( |
my $result = GetOptions( |
19 |
"list" => \$list_opt, |
"list" => \$list_opt, |
20 |
"add=s" => \$add_opt, |
"add=s" => \$add_opt, |
21 |
|
"queue=s" => \$queue_opt, |
22 |
"debug" => \$debug, |
"debug" => \$debug, |
23 |
); |
); |
24 |
|
|
37 |
my $lists = $loader->find_class('lists'); |
my $lists = $loader->find_class('lists'); |
38 |
my $users = $loader->find_class('users'); |
my $users = $loader->find_class('users'); |
39 |
my $user_list = $loader->find_class('user_list'); |
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) { |
if ($list_opt) { |
44 |
foreach my $list ($lists->retrieve_all) { |
foreach my $list ($lists->retrieve_all) { |
53 |
my $list = $lists->find_or_create({ |
my $list = $lists->find_or_create({ |
54 |
name => $add_opt, |
name => $add_opt, |
55 |
}) || die "can't add list $add_opt\n"; |
}) || die "can't add list $add_opt\n"; |
56 |
|
|
57 |
|
my $added = 0; |
58 |
|
|
59 |
while(<>) { |
while(<>) { |
60 |
chomp; |
chomp; |
61 |
next if (/^#/ || /^\s*$/); |
next if (/^#/ || /^\s*$/); |
69 |
user_id => $this_user->id, |
user_id => $this_user->id, |
70 |
list_id => $list->id, |
list_id => $list->id, |
71 |
}) || die "can't add user to list"; |
}) || die "can't add user to list"; |
72 |
|
$added++; |
73 |
} |
} |
74 |
|
|
75 |
foreach my $c_name ($loader->tables) { |
foreach my $c_name ($loader->tables) { |
77 |
$c->dbi_commit(); |
$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 --list --add=name_of_list --debug\n"; |
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 |
|
|
|
|
|