This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Getopt::Long qw{GetOptions}; | |
use lib "$ENV{LJHOME}/cgi-bin"; | |
BEGIN { require "ljlib.pl"; } | |
use LJ::Protocol; | |
use LJ::User; | |
our ( | |
$user, | |
$entry, | |
$comment, | |
$ditemid, | |
$parent, | |
$quick, | |
$nested, | |
); | |
sub usage { | |
die "Usage: $ARGV[0] [--user|-u] <user> [--entry|-e] <numentries> [--comment|-c] <numcomments> | --quick | --nested | --ditemid <entry id> | --parent <parent> \n"; | |
} | |
usage() unless GetOptions( | |
'u|user=s' => \$user, | |
'e|entry:i' => \$entry, | |
'c|comment:i' => \$comment, | |
'ditemid:i' => \$ditemid, | |
'parent:i' => \$parent, | |
'quick' => \$quick, | |
'nested' => \$nested, | |
); | |
usage() unless $user; | |
my $u = LJ::load_user(LJ::canonical_username($user)); | |
die qq#No such user "$user"# unless $u; | |
my $do_request = sub { | |
my ( $mode, %request_args ) = @_; | |
my $err = 0; | |
my %flags = %{ delete $request_args{flags} || {} }; | |
my $req = \%request_args; | |
$req->{username} ||= $u->user; | |
my $res = LJ::Protocol::do_request( $mode, $req, \$err, { noauth => 1, nocheckcap => 1, %flags } ); | |
return ( $res, $err ); | |
}; | |
sub post { | |
return $do_request->( "postevent", tz => "guess", @_ ); | |
}; | |
sub reply { | |
return $do_request->( "addcomment", @_ ); | |
}; | |
if ( $quick ) { | |
$entry = 5; # post 5 new entries | |
$comment = 10; # with 10 comments each | |
} else { | |
$entry ||= 1 if defined $entry; | |
$comment ||= 1 if defined $comment; | |
} | |
sub post_comment { | |
my ( $numcomments ) = @_; | |
return unless $numcomments; | |
for ( 1..$numcomments ) { | |
warn "posting comment $_\n"; | |
my ( $res, $err ) = reply( | |
ditemid => $ditemid, | |
parent => $parent, | |
body => "new comment to $user (in reply to $parent) " . rand(), | |
); | |
$parent = $res->{dtalkid} if $nested; | |
} | |
} | |
if ( $ditemid ) { | |
post_comment( $comment ); | |
} else { | |
for ( 1..$entry ) { | |
warn "posting entry $_\n"; | |
post( | |
subject => "here is a subject for the test post", | |
event => "new test post to journal " . rand(), | |
); | |
post_comment( $comment ); | |
} | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment