#!/usr/local/bin/perl -w ## ## A command which will go through a journal and ensure that all entries ## are at least made friends-only ## ## $Id: friends-only,v 1.3 2003/09/25 14:32:08 simes Exp $ ## use strict; # Silly not to be use POSIX; # For strftime() use LJ::Simple; # Kinda silly not to have this use Getopt::Std; # Options parsing use Data::Dumper; # For debugging ## Command line options # User name [-u] my $user=undef; # Password [-p] my $pass=undef; # Dry run [-n] ? my $DryRun=0; #$LJ::Simple::debug=1; sub usage() { my $cmd=(split(/\//,$0))[$#_]; my $spc=" "x(length($cmd)); print STDERR <; # chomp($ans); # $ans=lc($ans); # if ($ans!~/^y/) { # print STDERR "\nStopped at user request\n"; # exit 255; # } $|=0; } if (defined $user) { print STDERR "LJ Username: $user\n"; } else { $|=1; print STDERR "LJ Username: "; $user=; chomp($user); $|=0; } if (defined $pass) { print STDERR "LJ Password: \n"; } else { $|=1; system("stty -echo"); ($?!=0) && die "$0: Non-zero exit code [$?] returned by stty -echo\n"; print STDERR "LJ Password: "; $pass=; system("stty echo"); print STDERR "\n"; ($?!=0) && die "$0: Non-zero exit code [$?] returned by stty echo\n"; chomp($pass); $|=0; } print STDERR "Logging into LJ\n"; my $lj = new LJ::Simple({ user=>$user,pass=>$pass }); (defined $lj) || die "$0: Failed to log into LJ - $LJ::Simple::error\n"; # Now we need to go through all journal entries - fun print STDERR "Getting list of journal entries\n"; my ($num,@ItemId)=$lj->SyncItems(1); (defined $num) || die "$0: Failed to get item ids - $LJ::Simple::error\n"; print STDERR "Starting to process list of entries\n"; foreach (@ItemId) { ($_->{type} eq "L") || next; my %Entries=(); while (!(defined $lj->GetEntries(\%Entries,undef,"one",$_->{item_id}))) { warn "$0: Failed to get entries - $LJ::Simple::error\n"; warn "$0: retrying...\n"; } my $Entry; foreach $Entry (values %Entries) { my ($item_id,$anum,$html_id); while (!defined($item_id)) { ($item_id,$anum,$html_id)=$lj->GetItemId($Entry); last if defined $item_id; warn "$0: Failed to get item id - $LJ::Simple::error\n"; warn "$0: retrying...\n"; } my ($protect,@prot_opt); while (!defined $protect) { ($protect,@prot_opt)=$lj->GetProtect($Entry); last if defined $protect; warn "$0: Failed to get entry protection type - $LJ::Simple::error\n"; warn "$0: retrying...\n"; } my $ToProt=0; my $key=""; my $date=strftime("%Y-%m-%d %H:%M:%S",gmtime($lj->GetDate($Entry))); if ($protect eq "public") { $key="public"; $ToProt=1; } elsif ($protect eq "friends") { $key="friends only"; } elsif ($protect eq "groups") { $key=join("", "friends groups: ", join(", ",@prot_opt), ); } elsif ($protect eq "private") { $key="private"; } print "[$date] $item_id $anum = $key\n"; if ($ToProt) { if (!$DryRun) { print " Making entry friends-only\n"; $lj->SetProtectFriends($Entry); if (!$lj->EditEntry($Entry)) { warn "$0: Failed to edit entry - $LJ::Simple::error\n"; warn "$0: skipping...\n"; } } else { print " Not making friends-only [dry run]\n"; } } } }