Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Script]: Add bloggers to your livejournal friends list
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 26 Feb 2005
Posts: 19
Location: London

PostPosted: Tue Sep 06, 2005 4:18 pm    Post subject: [Script]: Add bloggers to your livejournal friends list Reply with quote

[Script]: Add bloggers to your livejournal friends list

I wrote this script because most of my contacts are on LiveJournal and so I have them added to my friends list. Unfortunately, you can't add people to your friends list unless they're on LJ themselves

1) emerge jlj
2) set up jlj to post as root using an LJ that's not your main identity
3) add that identity to your friends list
4) put this script in /etc/cron.hourly and chmod it
5) check your friends list. When someone posts, it will be added (note that existing posts are ignored, because this script is so simple that there's almost nothing that can go wrong. It also makes no attempt to clean up the HTML so you will get some random tags appearing all over the place)

I know this is a bit of a hack but I don't know how to use crontab, so when I was making it, I put it in /etc/cron.hourly, which requires it to be run as root. You will notice that jlj is not designed for use in scripts as it doesn't appear to give exit codes. This is why there's a hack in post() which uses grep to give me an exit status. If anyone wants to take the job of re-writing post() so that it doesn't have to rely on jlj (specifying username and password at the top of the script would be nice), I'd be pleased to change this script and bump up the version number. If anyone wants to do a quick hack for posting to a blogger page or something then post it and I'll add that in there too.

DISCLAIMER: This is only about the 3rd functional script I ever built, so if it sucks, don't blame me



#version 0.2 allows delayed posting of minor edits until something
#more substantial is added
#version 0.1 simply posted all additions or minor changes including
#jared's view count (religiously every hour for about a week :P )

#start defining variables here
# I think you need to re-define $HOME etc.
export HOME=/root
#add entries to anywhere, and comment out the ones you don't want
#duplicate entries will hopefully not matter, but will end up being
#downloaded multiple times just because I'm too lazy to check for them
#The temporary files are based on an md5sum of the URL, so that I
#don't have to bother with special characters etc. Just hex
#trailing slashes are NOT removed before the md5sum, and neither
#is the index.html part if you include it
#That's my LJ. Obviously there's no point in putting that on the list
#if you're using LJ anyway, but it's an example
blog="$blog "
blog="$blog "
blog="$blog "
blog="$blog "

#State how many lines you want to be added/changed before I post to LJ


# all files, including a copy of the blogger HTML page in question will
# be stored in this directory. Make sure you have permissions, and also
# make sure that its not going to get deleted


# finished defining variables. Start defining functions

        wget -o /dev/null -O "$dir/blog" "$1"

if [ -f "$dir/$1" ]
        diff  "$dir/$1" "$dir/blog" | grep "^>" | sed -e "s/^>//" > $dir/send
        result=`cat $dir/send | grep -c ".*"`
        if (( "$result > $lines" ))
                return 0
                return 1
        echo "warning: this blog has not been seen before. Nothing will be posted today" >> $dir/log
        mv $dir/blog $dir/$1
        return 1


        if [ "$?" = "0" ]; then
                echo "sending update of $1" >> $dir/log
                jlj -s -ne -es "<a href="$1">$1</a>" -bf "$dir/send" | grep -q "item posted"


        if [ "$?" = "0" ]; then
                mv "$dir/blog" "$dir/$sum" && rm "$dir/send" 
                echo "posting $1 failed" >> $dir/log
#finished defining functions. Now to stick it all together

mkdir -p $dir

date >> $dir/log

for i in $blog
        download $i
        sum=`echo "$i" | md5sum | sed -e "s/ *-//"`
        check $sum
        post $i
        clean $i
exit 0

<alsuren 22:07:55> I thought it was 42
<ladymauv 22:08:19> Maybe it's really 69
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum