Bash script to find mutual friends in Identica

I guess this is my first technical post involving script in it.

Starting this week, due to a recent change in my job role, I planned to spare my knowledge more on coding, along with technical aspects.

As a start, I came across my junior’s blog post yesterday about finding mutual friends in twitter. I thought to try one for Identica as well. As a result, I found the equivalent api’s for Identica. Here comes the code with a slight modification. Hope the below script is self explanatory.

#!/bin/bash

curl ‘http://identi.ca/api/friends/ids.json?screen_name=’$1 > .fol.tmp

curl ‘http://identi.ca/api/friends/ids.json?screen_name=’$2 > .fol2.tmp

cat .fol.tmp | sed ‘s/.*[([0-9,]*)].*/1/’ | sed ‘s/,/n/g’ | sort > .ids.tmp

cat .fol2.tmp | sed ‘s/.*[([0-9,]*)].*/1/’ | sed ‘s/,/n/g’ | sort > .ids2.tmp

#comm -12 is same as grep -xFf 🙂

grep -xFf .ids.tmp .ids2.tmp | tr ‘n’ ‘,’ | sed ‘s/,$//’ > .comids.tmp

comids=`cat .comids.tmp`

curl ‘http://identi.ca/api/users/show.json?user_id=’$comids > .lookup.tmp

cat .lookup.tmp | tr ‘,’ ‘n’ | grep ‘”name”‘ | sed ‘s/.*:”([^”]*)”/1/g’ > .show.tmp

#If loop to find if the file is empty. Read the man pages of test to understand the below logic.

if [[ -s .show.tmp ]] ; then

cat .show.tmp

else

echo “No mutual friends in Identica, Try with a different pair”

fi ;

rm .fol.tmp .fol2.tmp .ids.tmp .ids2.tmp .comids.tmp .lookup.tmp .show.tmp

The Output is as follows :

$ ./identica.sh ijeyanthan vigneshwaranr

No Identica followers, Try with a different pair

Unfortunately, not many people are using Identica and thus a very few followers.

This is applicable for any other StatusNet installs. The API root will be determined by whatever you set in your  in config file.

Eg :  http://www.yoursite.org/statusnet/api

and for Twitter, replace identica with http://api.twitter.com/1/,

Please add your suggestions & tips for better coding.

0 comments:

Leave a Reply

Your email address will not be published. Required fields are marked *