?

Log in

No account? Create an account
editevent stumped me... - LiveJournal Client Discussions [entries|archive|friends|userinfo]
LiveJournal Client Discussions

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

editevent stumped me... [Feb. 3rd, 2003|11:46 pm]
LiveJournal Client Discussions

lj_clients

[kimera]
I'm trying to write a script that will get eventid numbers from the RSS feed, delete all entries from the RSS page it downloads, then start the process again until no eventid numbers are found in the text. Despite the fact the script works, I keep getting the following error:

errmsg
Client error: Can't edit post from requested journal
success
FAIL


The code follows...


#!/usr/bin/perl -w

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

my $browser = LWP::UserAgent->new();
my $url = "http://turbov21.livejournal.com/rss";
my $lj_url = "http://www.livejournal.com/interface/flat";
my $response;

while (1) {
        $response = $browser->get($url);
        unless ($response->is_success) { print "Could not get $url\n"; exit; }

        my @response = split (/\n/, $response->content);
        my $line;
        my $endit;

        foreach $line (@response) {
                if ($line =~ m/itemid=(.*)/) {
                        my $event = $1;
                        $event =~ s/<\/link\>//g;
                        $event =~ s/\n//g;
                        print "$event\n";
                        &erase($event);
                        $endit = $event;
                }
        }

        unless ($endit) { exit; }
}

sub erase {
        my $itemid = $_[0];
        my $mode = "editevent";
        my $user = "turbov21";
        my $passwd = "password";
	my ($year, $mon, $day, $hour, $min) = &thetime;

        my $aresponse = $browser->post ( $lj_url,
                [
                        'mode' => $mode,
                        'user' => $user,
                        'password' => $passwd,
                        'itemid' => $itemid,
                        'event' => "",
                        'subject' => "",
			'year' => $year,
			'mon' => $mon,
			'day' => $day,
			'hour' => $hour,
			'min' => $min,
                ],
        );

        my $replied = $aresponse->content;
        print "$replied";
}

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);
}



I hate to ask, but I've read and re-read the editevent documentation over and over, but can come up with nothing. Can someone tell me what I'm doing wrong or at least point me in the direction of something similar? Thanks!
linkReply

Comments:
[User Picture]From: xb95
2003-02-03 11:22 pm (UTC)
Does editevent want the raw itemid or the itemid after anum has been multiplied in? Don't forget that the itemid you get from rss pages is usually not the one that you have to use when talking to the server. I forget the exact order, but you should really be using syncitems and getevents to download things. Using the RSS feed is probably asking for trouble.
(Reply) (Thread)
[User Picture]From: kimera
2003-02-04 06:19 am (UTC)
Oh. I did not know those things. Thank you.
(Reply) (Parent) (Thread)
[User Picture]From: benzado
2003-02-04 07:49 am (UTC)
You're writing a journal deleter? Dare I ask why?

Why don't you use syncitems to get the itemids of all the posts (no anum fiddling necessary) and the remove them all?
(Reply) (Thread)
[User Picture]From: kimera
2003-02-04 08:02 am (UTC)

Because it's there?

I see LJ as more of a platform for software development -- client writing, etc. -- than a journal. Since no one has ever created a deleter before -- that I knew of -- it seemed like a decent challenge.

I went with getevents for this initial version, but I'll most likely revise the code later this week.

Here is a copy of the semi-working code if anyone wants it.
(Reply) (Parent) (Thread)
[User Picture]From: kimera
2003-02-04 08:26 am (UTC)

bah...

(Reply) (Parent) (Thread)