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."; }

In reply to Trying to submit a comment to Typepad Blog using Perl Mechanize by Anonymous Monk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.