Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/local/bin/perl -w # # READ THE SECURITY NOTICE BELOW! # # This is for people that run around life with the all important voti +ng nodelet turned off. # Don't you hate suddenly seeing what appears to be an off-topic thre +ad, only to realize # that a new voting booth has been put up, and you're not in on the a +ction? # # Well, thanks to Twitching Monk Software's latest release, you can b +e a member of the # trendy 'Vote Early, Vote Often' crowd. Simply tune the parameters +below for your # mail server and account, toss it in a cron job, and voting glory wi +ll be yours (and # remember... All your vote are belong to us!) # # This script gets the past polls page, compares it to the previous p +age stored in the # __DATA__ section of the script. If they're different, an email is +sent, and if the email # succeeds, the script rerites itself. I highly recommended that thi +s be set to '600' # permission set. # # I'd probably recommend that a copy of the script be made, once you' +ve set the parameters, # just in case it manages to corrupt itself somehow. It's not likely +, but anything is # possible with a TMS release. If you felt really tricky, when the s +cript is first run # with nothing after the data section, it would get the length of the + script, and write # that as part of the data section. Then, after it stripped off the +old __DATA__, it would # perform a check to see if it's still the same length as what it was +, and abort if not. # # SECURITY NOTICE: Set this script to 600 permission. You don't wan +t other people re- # writing it for you, with something far nastier th +an checking for a # new voting nodelet. Like, oh say, posting DiscoS +tu quality articles # under your user ID... Or erasing all your tetris + high scores. # # Requires the following modules: # LWP::Simple # MIME::Lite # # Copyright 2000,2001(c) J.C.Wren jcwren@jcwren.com # A production of Twitching Monk Software # No rights reserved, use as you see fit. I'd like to know about it, + though, just for kicks. # # 2001/03/18 - 1.00.00 - Initial release # 2001/03/18 - 1.10.00 - dkubb's optimized file handling, and fix of +a potential bug if # vroom ever started including \n's in the dis +playtype=raw pages. # use strict; use LWP::Simple; use MIME::Lite; # # Tune these to your requirements # use constant cMailto => '"A. User Name" <pmuser@mysite.com>'; + # who the mail goes to use constant cMailfrom => '"A. User Name" <pmuser@mysite.com>'; + # from is the same as to, for me use constant cMailsubject => 'Perlmonks.org New Voting Booth Up!'; + # subject line in message use constant cMailserver => 'localhost'; + # mailserver to use use constant cMailtext => "New voting booth is up at the monastery. +"; # what to send in the body use constant cSite => "http://www.perlmonks.org/index.pl?node=p +ast%20polls&displaytype=raw"; { $LWP::Simple::FULL_LWP = 1; my $newpage = get (cSite) or die "Eeek! Can't get page from site"; read DATA, my $oldpage, -s DATA; if (!defined ($oldpage) || $oldpage ne $newpage) { MIME::Lite->send ('smtp', cMailserver, Timeout=>60); my $msg = MIME::Lite->new (From => cMailfrom, To => cMailto, Subject => cMailsubject, Type => 'TEXT', Encoding => '7bit', Data => cMailtext) or die "Eeek! + MIME::Lite->new failed"; $msg->send or die "Eeek! MIME::Lite->send failed."; # # Only update if we actually sent the message # open SELF, "+< $0" or die "Eeek! Can't open $0: $!"; { local $/ = join '', $/, '__DATA__'; <SELF>; } (truncate SELF, tell SELF) || die "Eeek! Truncate failed: $!"; print SELF $/, $newpage; close SELF; } } __DATA__

Old version, prior to dkubbs suggestions

#!/usr/local/bin/perl -w # # READ THE SECURITY NOTICE BELOW! # # This is for people that run around life with the all important voti +ng nodelet turned off. # Don't you hate suddenly seeing what appears to be an off-topic thre +ad, only to realize # that a new voting booth has been put up, and you're not in on the a +ction? # # Well, thanks to Twitching Monk Software's latest release, you can b +e a member of the # trendy 'Vote Early, Vote Often' crowd. Simply tune the parameters +below for your # mail server and account, toss it in a cron job, and voting glory wi +ll be yours (and # remember... All your vote are belong to us!) # # This script gets the past polls page, compares it to the previous p +age stored in the # __DATA__ section of the script. If they're different, an email is +sent, and if the email # succeeds, the script rewrites itself. I highly recommended that th +is be set to '600' # permission set. # # I'd probably recommend that a copy of the script be made, once you' +ve set the parameters, # just in case it manages to corrupt itself somehow. It's not likely +, but anything is # possible with a TMS release. If you felt really tricky, when the s +cript is first run # with nothing after the data section, it would get the length of the + script, and write # that as part of the data section. Then, after it stripped off the +old __DATA__, it would # perform a check to see if it's still the same length as what it was +, and abort if not. # # SECURITY NOTICE: Set this script to 600 permission. You don't wan +t other people re- # writing it for you, with something far nastier th +an checking for a # new voting nodelet. Like, oh say, posting DiscoS +tu quality articles # under your user ID... Or erasing all your tetris + high scores. # # Requires the following modules: # LWP::Simple # MIME::Lite # # Copyright 2000,2001(c) J.C.Wren jcwren@jcwren.com # A production of Twitching Monk Software # No rights reserved, use as you see fit. I'd like to know about it, + though, just for kicks. # use strict; use LWP::Simple; use MIME::Lite; # # Tune these to your requirements # use constant cMailto => '"A. User Name" <pmuser@mysite.com>'; + # who the mail goes to use constant cMailfrom => '"A. User Name" <pmuser@mysite.com>'; + # from is the same as to, for me use constant cMailsubject => 'Perlmonks.org New Voting Booth Up!'; + # subject line in message use constant cMailserver => 'localhost'; + # mailserver to use use constant cMailtext => "New voting booth is up at the monastery. +"; # what to send in the body use constant cSite => "http://www.perlmonks.org/index.pl?node=p +ast%20polls&displaytype=raw"; { $LWP::Simple::FULL_LWP = 1; my $newpage = get (cSite) or die "Eeek! Can't get page from site"; my $oldpage = <DATA>; if (!defined ($oldpage) || $oldpage ne $newpage) { MIME::Lite->send ('smtp', cMailserver, Timeout=>60); my $msg = MIME::Lite->new (From => cMailfrom, To => cMailto, Subject => cMailsubject, Type => 'TEXT', Encoding => '7bit', Data => cMailtext) or die "Eeek! + MIME::Lite->new failed"; $msg->send or die "Eeek! MIME::Lite->send failed."; # # Only update if we actually sent the message # { local $/ = undef; open (FH, "<$0") or die "Eeek! Can't open myself for reading +!"; my $self = <FH>; close (FH); $self =~ s/(^__DATA__$).*/$1/m; $self .= $newpage; open (FH, ">$0") or die "Eeek! Can't open myself for writing +!"; print FH $self; close (FH); } } } __DATA__

In reply to Voting Booth Nodelet Watcher by jcwren

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (10)
    As of 2015-07-02 12:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (36 votes), past polls