Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've written a routine that submits a comment to a Typepad blog via the Perl Mechanize routine. The comment is actually generated in an iphone app and the perl script acts just as a relay taking the comment/username/url from the iphone using form POST. The perl script then goes to the blog post, generates the comment and presses 'submit'.

The problem is that it works *sometimes*. This I do not understand. Why does it work sometimes? Is it my script or is it Typepad? Here is the script below. Sometimes the post does not go through but I still get a status of '200' back from Typepad. Alternatively, anyone know any API's or other methods for posting a comment on Typepad? I've looked at their APIs and they do not have anything that will post a comment....the APIs are only able to add a blog post.

#!/usr/local/bin/perl require "../cgi-lib.pl"; print "Content-type: text/html\n\n"; &ReadParse(*F); my $error = ''; $author = $F{'author'}; # username of the person posting $email = $F{'email'}; # users email address $comment = $F{'comment'}; # comment to submit $comment =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;; $url = $F{'url'}; # the url of the blog post $url =~ s/\/comments\/atom.*/\.html/; chomp($url); if ($author eq '') { $author = 'Anonymous'; } if ($email eq '' ) { $error .= 'Email was blank. Comment not posted'; +} if ($comment eq '' ) { $error .= 'Error: Comment was blank.'; } if ($error ne '' ) { print $error; exit; } use LWP::Simple; use WWW::Mechanize; use HTTP::Cookies; my $m = WWW::Mechanize->new( autocheck=>1); $m->get($url); print $m->response->status_line; if ($m->success) { $m->form('comment-form'); $m->field('author',$author); $m->field('email',$email); $m->field('url',''); $m->field('text',$comment); $m->click('post'); print "Your comment has been posted."; print $m->response->status_line; } else { print "Was not able to connect to website."; }

Replies are listed 'Best First'.
Re: Trying to submit a comment to Typepad Blog using Perl Mechanize
by Anonymous Monk on Jul 16, 2009 at 03:10 UTC
    The problem is that it works *sometimes*. This I do not understand. Why does it work sometimes? Is it my script or is it Typepad?

    You need to examine the response to figure out why, but you shouldn't use cgi-lib.pl, it is a genuine antique. use CGI instead ( or CGI::Simple...).

      I know it is antique, but it is a small lib and loads quicker and I'm looking for speed here. As it is it takes a few seconds to respond. Anyone have any other suggestions on how to do this?
        I know it is antique, but it is a small lib and loads quicker and I'm looking for speed here.

        So you prefer hitting yourself over the head with a rock , because it is faster than taking an aspirin?

        cgi-lib was already outdated/broken for years when it was retired 10 years ago.

        CGI::Simple is faster than CGI