Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2024-04-23 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found