Permalink
Browse files

Merge branch 'xml-twig'

OK, nobody screamed bloody murder at me, so apparently I didn't blow
up the entire website or anything. Merging my cleanup into master.
  • Loading branch information...
jhannah committed Jun 29, 2013
2 parents 00260b9 + 6ac993b commit 42a935dea61451c044af2a284fe02798a442541c
Showing with 143 additions and 146 deletions.
  1. +74 −11 bin/deactivate.pl
  2. +69 −135 perl_mongers.xml
View
85 bin/deactivate.pl 100644 → 100755
@@ -1,42 +1,105 @@
+#! env perl
+
use 5.18.0;
use Email::Stuffer;
+use XML::Twig;
+
+my $xml = 'perl_mongers.xml';
+my $name = $ARGV[0] || usage();
+
+my ($elt) = update_xml($name);
+send_email($elt);
+say "Deactivated in XML. Email sent.";
+
+exit;
+
+# ------------
+# END MAIN
+# ------------
+
+sub usage {
+ print <<EOT;
+
+$0 Omaha.pm
-send_email('Omaha.pm', 'http://omaha.pm.org', 'jay@jays.net');
+EOT
+ exit;
+}
+
+
+sub update_xml {
+ my ($name) = @_;
+ my $found_it = 0;
+ my $elt;
+ my $twig = XML::Twig->new(
+ pretty_print => 'indented',
+ # output_text_filter => 'html',
+ twig_handlers => {
+ group => sub {
+ if ($_->first_child('name')->text eq $name) {
+ $_->{att}->{status} = 'inactive';
+ $found_it++;
+ $elt = $_;
+ }
+ },
+ },
+ );
+ $twig->parsefile($xml);
+ unless ($found_it) {
+ die "Didn't find group '$name'";
+ }
+ open my $new, '>:utf8', 'new.xml' or die;
+ print $new $twig->sprint;
+ close $new;
+ rename('new.xml', $xml);
+ return $elt;
+}
sub send_email {
- my ($group, $homepage, $leader_email) = @_;
+ my ($elt) = @_;
- $leader_email = 'jay@jays.net'; # temporary
+ my $group_name = $elt->first_child('name')->text;
+ my $tsar = $elt->first_child('tsar')->first_child('name')->text;
+ my $e = $elt->first_child('tsar')->first_child('email');
+ my $tsar_email =
+ $e->first_child('user')->text . '@' .
+ $e->first_child('domain')->text;
+ my $web = $elt->first_child('web')->text;
my $body = <<EOT;
<p>
-$group leader,
+$tsar,
</p><p>
It appears that your Perl Mongers group configuration is broken,
badly out of date, or has been overrun with spam:
</p><p>
- $homepage
+ $web
</p><p>
Your group has been deactivated.
</p><p>
When you have resolved the problem(s), please reply to this email
informing us of your resolutions so that we can re-activate you.
</p><p>
+If we have made a mistake, we apologize. Please reply so we know something
+has gone wrong on our side.
+</p><p>
Thank you for your attention!
</p><p>
-pm.org support staff<br/>
-support\@pm.org
+pm.org support staff &lt;support\@pm.org&gt;<br/>
+Group hosting FAQ: http://www.pm.org/faq/hosting_faq.html
</p>
EOT
-
+
# Create and send the email in one shot
+ say "Sending to $tsar_email";
Email::Stuffer
->from ('support@pm.org')
- ->to ($leader_email)
- ->subject ("$group deactivated")
+ ->to ($tsar_email)
+ ->cc ('jay@jays.net')
+ ->subject ("$group_name deactivated")
->html_body($body)
- ->send;
+ ->send || die $!;
}
Oops, something went wrong.

0 comments on commit 42a935d

Please sign in to comment.