/[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 2 - (show annotations)
Fri May 13 22:08:44 2005 UTC (18 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1799 byte(s)
a try at add option

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 my ($list_opt,$debug) = (0,0);
9 my $add_opt;
10
11 my $result = GetOptions(
12 "list" => \$list_opt,
13 "add=s" => \$add_opt,
14 "debug" => \$debug,
15 );
16
17
18 my $loader = Class::DBI::Loader::Pg->new(
19 debug => $debug,
20 dsn => "dbi:Pg:dbname=notices",
21 user => "dpavlin",
22 password => "",
23 namespace => "Noticer",
24 # additional_classes => qw/Class::DBI::AbstractSearch/,
25 # additional_base_classes => qw/My::Stuff/,
26 relationships => 1
27 );
28
29 my $lists = $loader->find_class('lists');
30 my $users = $loader->find_class('users');
31 my $user_list = $loader->find_class('user_list');
32
33 if ($list_opt) {
34 foreach my $list ($lists->retrieve_all) {
35 print $list->name,"\n";
36 foreach my $user_on_list ($user_list->search(list_id => $list->id)) {
37 my $user = $users->retrieve( id => $user_on_list->user_id );
38 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 {
68 die "$0 --lists --list-add=name_of_list --debug\n";
69 }
70
71

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26