[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 138
  • Last Modified:

Trying to automate a content checker

I have websites everywhere that I have to check regularly for new content.  I'm trying to automate this and for starters I want to automate a mail check at mail.com.  When you login to this site the thing I normally see is:

0 Unread Message(s), 0 New Message

What I'm envisioning is that every 5 minutes I want to:

1) login to mail.com
2) if I find "Messages(s), 0 New" in the content, I logout and go back to sleep
3) Anything else I want to text message myself on my phone by emailing to xxx-xxx-xxxx@cell.company.email with a "new content available" sort of message

Then I can just start up the perl in the AM and leave it running.  No more having to go and look.  As time goes on I can plug in other places to check.  EE iteslf, hotmail, pop3 mails, other BBs that I'm on.  I can probably buy myself an hour or so a day with this idea.

Can somebody help me out with a script that implements this ?

while true do  {
    if check_mail_dot_com_function returns TRUE then
        email my pager
    #
    # calls to other automated content check functions can go here
    #
    sleep for 5 minutes
    }

check_mail_dot_com_function  {
    login to website
    if "0 new" in content {
        logout of website
        return FALSE
    } else {
        logout of website
        return TRUE
    }
}
0
_Scotch_
Asked:
_Scotch_
  • 4
  • 3
1 Solution
 
Adam314Commented:
Would you want it to continually text message you, or only once per new set of messages?

eg: at 10:00 you get 1 new message.  at 10:05, you still haven't checked your e-mail, so it still says 1 new message.  at 10:10, you still haven't checked your e-mail, so it still says 1 new message.

Or would you want it to check the number of new messages, and only text message when the number changes?
0
 
_Scotch_Author Commented:
Oh.  I didn't think that far. Yes I guess that the checker function would have to store the last count and if it *increases* then it returns TRUE.  
0
 
_Scotch_Author Commented:
Oh.  I didn't think that far. Yes I guess that the checker function would have to store the last count and if it *increases* then it returns TRUE.  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Adam314Commented:
Using the LWP modules, you should be able to do what you need.

Info on the LWP module
http://search.cpan.org/~gaas/libwww-perl-5.805/lib/LWP.pm


Here is some sample code, taken from this question: http:Q_20991473.html
#! /usr/bin/env perl

use LWP;
use HTTP::Cookies;
use HTTP::Request::Common;

my $url = "http://mail.com";

my $ua = LWP::UserAgent->new;
$cookie_jar = HTTP::Cookies->new( file=>'cookies.txt', autosave=>1);
$ua->cookie_jar($cookie_jar);
$ua->agent( 'Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Creative)');
push @{ $ua->requests_redirectable }, 'POST';

my $req = POST $url,
   [
     redirectURL=>"/Programming/Programming_Languages/Perl/",
     msu_loginName=>'jmcg',
     msu_password=>'no-not-my-real-password',
     msu_rememberMe=>'ON',
     Login=>'Login',
   ];


$res = $ua->request( $req);

if( $res->is_success) {
  print $res->content;
  } else {

  print 'Error: ', $res->status_line, "\n";
  print "===== Request Headers =====\n";
  print $req->headers->as_string;
  print "===== Response Headers ====\n";
  print $res->headers->as_string;
  print "===== Response Content ====\n";
  print $res->content;
  exit 1;
  }
0
 
_Scotch_Author Commented:
I don't understand how this stuff here is supposed to get me logged into mail.com ???

my $req = POST $url,
   [
     redirectURL=>"/Programming/Programming_Languages/Perl/",
     msu_loginName=>'jmcg',
     msu_password=>'no-not-my-real-password',
     msu_rememberMe=>'ON',
     Login=>'Login',
   ];
0
 
_Scotch_Author Commented:
Nevermind.  Thanks for trying though.  This code snippet gets me to the interesting part of the content:


use WWW::Mechanize;

my $mail_com_url = 'http://www.mail.com/scripts/common/index.main?signin=1&lang=us';
my $mail_com_username = 'a valid username';
my $mail_com_password = 'a valid password';
my $mech = WWW::Mechanize->new();

$mech->agent_alias('Windows IE 6');
$mech->get($mail_com_url);
die 'error getting main mail.com page', $mech->response->status_line, unless $mech->success;
#$mech->form_number(1);
$mech->field('login', $mail_com_username);
$mech->field('password', $mail_com_password);
$mech->submit();
$mech->follow_link(n => 2);
print $mech->content();
0
 
Adam314Commented:
Glad you got it working
0
 
DarthModCommented:
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now