Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rcaputo (9040)

rcaputo
  (email not shown publicly)
http://poe.perl.org/

Journal of rcaputo (9040)

Monday July 13, 2009
01:17 AM

Test post, please ignore.

[ #39282 ]

BinGOs pointed out WWW::UsePerl::Journal and kindly pasted the code he uses to drive it. I've hacked it a little to embed the article title into a header block on the article. Since I'm writing these offline, I figure the title should be associated with the article for posterity.

Here's my hacked version of BinGOs' posting script:

#!/usr/bin/env perl

use warnings;
use strict;

use WWW::UsePerl::Journal;

my $user = 'rcaputo';
my $pass = '********';

# Headers.

my $title;
my $comments = 1;

while (<>) {
    chomp;
    last if /^\s*$/;

    unless (/^\s*([^:]+?)\s*:\s*(\S.*?)\s*$/) {
        die "Unknown header line ($_)\n";
    }

    my ($header, $value) = (lc($1), $2);

    # Avoid the lulz.
    $value =~ s/\Q$pass/********/g;

    if ($header eq "title") {
        $title = $value;
        next;
    }

    if ($header eq "comments") {
        if (lc($value) eq "yes") {
            $comments = 1;
        }
        elsif (lc($value) eq "no") {
            $comments = 0;
        }
        else {
            die "Comments header may only be yes or no.\n";
        }
    }
}

# Body HTML.

my $text = '';
while (<>) {
    # Only one per line.
    if (/^\s*<ecode\s*file="([^"]+)"\s*\/*\s*>\s*$/) {
        my $code = `/bin/cat $1`;
        $code =~ s/\n+$//;

        # Break up the ecode tags so this script can
        # present itself.
        $_ = "<" . "ecode>\n$code\n<" . "/ecode>";
    }

    $text .= $_;
}

# Avoid the lulz.
$text =~ s/\Q$pass/********/g;

die "Article needs a Title header.\n" unless $title;
die "Article needs body HTML.\n" unless $text;

# Post.

my $journal = WWW::UsePerl::Journal->new($user);
my $post = $journal->login($pass);

unless (
    $post->postentry(
        title    => $title,
        text     => $text,
        topic    => 34,         # user journal
        comments => $comments,  # allow comments?
        type     => 2,          # ???
        promote  => 'publish',  # ???
    )
) {
     die "Failure.\n";
}

print "Success.\n";
exit;

Here's the source of this article:

Title: Test post, please ignore.

<p>
    BinGOs pointed out WWW::UsePerl::Journal and kindly pasted the code
    he uses to drive it.  I've hacked it a little to embed the article
    title into a header block on the article.  Since I'm writing these
    offline, I figure the title should be associated with the article
    for posterity.
</p>

<p>
    Here's my hacked version of BinGOs' posting script:
    <ecode file="~/bin/useperlpost.pl"/>
</p>

<p>
    Here's the source of this article:
    <ecode file="~/Documents/useperl/testing-www-useperl-journal.html"/>
</p>

<p>
    Thanks for reading anyway.
</p>

Thanks for reading anyway.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.