Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Let me know if it's gonna snow!

by newrisedesigns (Curate)
on Feb 07, 2003 at 03:28 UTC ( #233357=CUFP: print w/ replies, xml ) Need Help??

Monitor your university's emergency webpage (or any page) for changes. You can use this, for example, to check for the addition of snow cancellation data. If there is a change, audibly let it be known.

#!/usr/bin/perl -w use strict; use LWP::Simple; use Digest::MD5; use constant 'PAGE' => 'http://www.rowan.edu/emergency/'; my $d = Digest::MD5->new(); my $data = get(PAGE); $d->add($data); my $original = $d->digest; print "Monitoring " . PAGE . "\n"; while(sleep(60*5)){ print "getting page...\n"; $data = get(PAGE); my $d = Digest::MD5->new(); $d->add($data); my $latest = $d->digest; if($latest ne $original){ use Win32::OLE qw( EVENTS ); my $DirectSS = new Win32::OLE( "{EEE78591-FE22-11D0-8BEF-00600 +81841DE}" ) or die "$!"; my $say = "The watched page eventually boils. Your page has ch +anged."; print "Page has been updated!!!\n"; $DirectSS->Speak($say); while( $DirectSS->{Speaking} ){ Win32::OLE->SpinMessageLoop(); Win32::Sleep( 100 ); } exit; } print "no change.\n"; }

Quick and dirty script. Comments and questions encouraged. See a bug? Let me know!

John J Reiser
newrisedesigns.com

Comment on Let me know if it's gonna snow!
Download Code
Re: Let me know if it's gonna snow!
by jdporter (Canon) on Feb 07, 2003 at 16:43 UTC
    It should be noted (somewhere) that once a page difference is detected, it continues to be announced (every x minutes) as long as the page is different from the original at the time the script was launched.
    And then there's the possibility that if the content of the page changes back to the original, the announcements will cease.
    Therefore the user will have to stop the script and restart it if she wants to detect another page change.

    One thing I would do is put the page getter/digester into a subroutine:
    sub page_hash { my $d = Digest::MD5->new(); $d->add( get( PAGE ) ); $d->digest }
    Then you can say
    my $original = page_hash(); . . . if ( $original ne page_hash() ) . . .

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.

      The program "exit"s just after it is done speaking.

      Does this work differently for you?

      Thanks,

      John J Reiser
      newrisedesigns.com

        Opps -- Missed that.

        jdporter
        The 6th Rule of Perl Club is -- There is no Rule #6.

Re: Let me know if it's gonna snow!
by Anonymous Monk on Feb 10, 2003 at 12:23 UTC
    Side comment, but you could also write a little java (cough evil cough) app that would use the freetts speach library that would just speak whatever, thus, allowing for similiar functionality for non windows machines.... Speaking of which, is there native perl text 2 speach engine (just out of curiosity?) Cheers..
Re: Let me know if it's gonna snow!
by perrin (Chancellor) on Feb 13, 2003 at 22:43 UTC
    Two comments:

    First, it doesn't make sense to use Win32::OLE in the middle of the program. Do it at the top with everything else. If you were trying to only load this under certain conditions, change it to a require and import instead.

    Second, I used the Festival TTS system from Perl years ago to make talking stock ticker in a few lines of code. At the time I had to make it fork a LISP program to do this, but there are now interfaces to Festival available on CPAN.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://233357]
Approved by data64
Front-paged by gmax
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-10-21 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (95 votes), past polls