?

Log in

No account? Create an account
lj-cron? - LiveJournal Client Discussions [entries|archive|friends|userinfo]
LiveJournal Client Discussions

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

lj-cron? [Jun. 13th, 2003|12:26 pm]
LiveJournal Client Discussions
lj_clients
[fishfoo]
Do any of the currently distributed clients have a function to delay posts until a preset time? I'd like to draft some posts locally, then have them automatically posted to my journal at midnight each evening.

If I were better at network coding, I'd kludge together an at-script myself. But I suck at network coding, and why reinvent the wheel if someone's already done it?
linkReply

Comments:
[User Picture]From: jarodrussell
2003-06-13 01:50 pm (UTC)
Here ya go... Basically, save a file in the $entries directory in the format of year, month, day, hour minute. For instance, if I made an entry file now, its filename would be 200306131546 -- no extensions or anything, just the number. The code, run through cron every few hours, should do the rest.


#!/usr/bin/perl -w

use strict;
use LWP 5.64;
use HTTP::Response;

my $ljurl = 'http://www.livejournal.com/interface/flat';
my $browser = LWP::UserAgent->new;
my $homepath = '/home/superboy/projects/ljpost';
my $idfile = 'ljid.txt';
my $logfile = 'ljlogs.txt';
my $entrydir = 'ljentries';
my ($id, $pw) = &getid();
my ($year, $mon, $day, $hour, $min) = &thetime();
my $thistime = join ('', $year, $mon, $day, $hour, $min);
my @topostentries = &getlist();

foreach my $topost (@topostentries) {

        # local
        my $thpost = $homepath . '/' . $entrydir . '/' . $topost;
        my $thelog = $homepath . '/' . $logfile;
        my $mode = "postevent";

        open (GETPOST, "$thpost") || die "Could not open $thpost\n";
        my @gotpost = <GETPOST>;
        close (GETPOST) || die "Could not close $thpost\n";

        my $gotpost = join ("\n", @gotpost);

        my $response = $browser->post ( $ljurl,
        [
                        'mode' => $mode,
                        'user' => $id,
                        'password' => $pw,
                        'event' => $gotpost,
                        'year' => $year,
                        'mon' => $mon,
                        'day' => $day,
                        'hour' => $hour,
                        'min' => $min,
                ],
        );

        open (UPLOG, ">>$thelog") || die "Could not open $thelog\n";
        print UPLOG $response->content, "\n";
        close (UPLOG)|| die "Could not close $thelog\n";

        unlink $thpost;
}

exit;

#####

# Gets the id
sub getid {

        # local
        my $openidfile = $homepath . '/' . $idfile;

        open (GETID, "$openidfile") || die "Could not open $openidfile\n";
        my $idinfo = <GETID>;
        close (GETID) || die "Could not close $openidfile\n";

        $idinfo =~ s/\n//g;
        $idinfo =~ s/\r//g;

        my @stuff = split (/\|/, $idinfo);

        return ($stuff[0], $stuff[1]);
}

# Gets the time
sub thetime {

        # this part is used to get the date and time of the entry.
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime(time);

        if ($min < 10) { $min = "0$min"; }
        if ($hour < 10) { $hour = "0$hour"; }
        if ($mday < 10) { $mday = "0$mday"; }
        $mon = $mon + 1;
        if ($mon < 10) { $mon = "0$mon"; }
        $year = $year + 1900;

        return($year, $mon, $mday, $hour, $min);
}

# This gets a list of entries from the entry directory
sub getlist {

        # local variables
        my $entrypath = $homepath . '/' . $entrydir;
        my @list = <$entrypath/*>;
        my $fcnt = 0;
        my @ifexist = ();

        foreach my $listfile (@list) {
                $listfile =~ s/$entrypath\///g;
                if ($listfile <= $thistime) {
                        push (@ifexist, $listfile);
                }
        }

        return (@ifexist);
}

(Reply) (Thread)
From: fishfoo
2003-06-20 06:40 am (UTC)
Keen. I'm getting the following in ljlogs.txt, though:

errmsg
Client error: No username sent.
success
FAIL


What's going wrong? I think I probably have incorrect syntax in the ljid.txt file... what should that file look like?

Thanks!

(Reply) (Parent) (Thread)
[User Picture]From: jarodrussell
2003-06-20 07:33 am (UTC)
The idfile.txt line should look like this:

jarodrussell|password
(Reply) (Parent) (Thread)
From: fishfoo
2003-06-20 07:39 am (UTC)
Schweetness. Works like a charm. Thank you!
(Reply) (Parent) (Thread)
[User Picture]From: jarodrussell
2003-06-20 07:41 am (UTC)
Glad to be of service.
(Reply) (Parent) (Thread)
[User Picture]From: gaal
2003-06-13 01:52 pm (UTC)
logjam can be used to send posts from the command line, so that you can use it as you would use mail(1) to send email in a script. You can run it in GUI mode first to write up your entry and then save it as a draft if you like.
(Reply) (Thread)
[User Picture]From: gharris
2003-06-23 01:12 pm (UTC)
I currently use jlj for that (and all my postings for that matter). You simply write up and entry as normal, but use the '-o' switch, which tells it to go offline. In a cron job, you tell it to flush all pending posts ('-f' switch). Very simple.

--Glenn
(Reply) (Thread)