Slash Boxes
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Just used this to post a test-entry [] into my journal. It's probably about on-par with the test script pudge was using a while back, except that the path to the cookie file is UNIX-ish instead of Mac-ish (and File::Spec wouldn't really help here, because the different Netscape platforms save their user data in differently-formed paths). It also allows for command-line arguments for title and whether to allow discussion. It also allows a command-line-provided filename to provide the body, or in absence of it reads from STDIN. It doesn't handle the other options to add_entry because they're integer-oriented, which would be useless to an end-user without some text-to-value mapping (pudge: another subject for our off-line architecture discussion). But it's a start, and might be good cut-and-paste fodder for someone else. I'll be adding the non-Netscape cookie support later.

    #!/usr/bin/perl -w

    use strict;

    use Getopt::Std;

    use HTTP::Cookies;
    use SOAP::Lite;
    use XML::RSS;

    my %opts;
    getopts('c:u:m:f:', \%opts) or die <<"USAGE";
    Usage: $0 [ -m title ] [ -f file ] [ -c yes|no ]

    -m title        Provide title for the journal entry
                    (default is command name-based)
    -f file         Read the journal entry from FILE instead of STDIN
    -c yes|no       Allow or disallow comments
                    (default is to let your default stand)


    my $title       = $opts{'m'} || "Generated by $0";
    my @discuss     = (exists $opts{c}) ?
                          (discuss => $opts{c} =~ /yes/i ? 1 : 0) : ();
    my $readfh;
    if ($opts{f})
        open(FILE, "< $opts{f}") or die "$0: Error opening $opts{f}: $!\n";
        $readfh = \*FILE;
        $readfh = \*STDIN;
    my $body = join('', <$readfh>);

    my $host        = '';
    my $uri         = "http://$host/Slash/Journal/SOAP";
    my $proxy       = "http://$host/";
    my $cookie_file = "$ENV{HOME}/.netscape/cookies";

    my $cookie_jar  = HTTP::Cookies::Netscape->new;

    my $journal = SOAP::Lite
                      ->proxy($proxy, cookie_jar => $cookie_jar);
    my $result = $journal->add_entry(subject => $title,
                                     body    => $body,
    print $result ?
        "New entry added as $result\n" : "Entry was not added\n";