Jump to content

Recommended Posts

Posted

fbcmd is a command line interface for Facebook (Probably deserves a segment!). Yesterday I saw the HakTip about Festival, a free TTS engine for Linux. I knew the two needed to be combined, so I made a bash script that reads out the latest post from your Facebook stream!

(Skip to the bottom for the completed script)

You Will Need:

Festival

fbcmd

Getting Festival

$ sudo apt-get install festival

Getting FBCMD

Follow the instructions here http://fbcmd.dtompkins.com/installation

How I started (aka the one line version)

fbcmd stream 0 1 | grep -v [#] | cut -d "]" -f 2- | festival --tts --pipe

fbcmd stream 0 1

"fbcmd stream" gives you the latest 10 updates from your stream. The first argument is the "importance" level of the updates to be output, 0 means show all. The second argument is the number of updates to show.

It also outputs a header row with column labels, we don't need this so....

grep -v [#]

grep -v outputs everything except lines that contain the argument. In this case "[#]". If you look at the usual output of "fbcmd stream" it is a numbered list with a header row, the header row contains [#], which is unlikely to appear in anyone's status.

cut -d "]" -f 2-

In this case, cut is being used to take off the first few characters of the output (The numbering column). I don't think this is strictly the way cut is meant to be used, if anyone has a better way, let me know!

festival --tts --pipe

Uses TTS to read out everything that is piped into it!

But I've already heard that update! (aka. the long version)

After I got all this working, I thought it would be better to only read out the update if it hadn't been read before (So it could be used on a timer, to give updates once a minute for example, but only if there is a new one)

#!/bin/bash
# Gets latest update from Facebook stream
echo `fbcmd stream 0 1 | grep -v [#]` >> .facebook1

# Check to see if script has been run before
if [ -a .facebook2 ]	
	then
# If it has it checks to see if this status is different	
	FILE1=`cat .facebook1`	
	FILE2=`cat .facebook2`	
	if [ "$FILE1" == "$FILE2" ]	
     then	
     festival --tts .facebook1
	fi
else	
	festival --tts .facebook1
fi
# Moves status to a secondary file to be checked next time
mv .facebook1 .facebook2

Ending stuff

I'm not very advanced at bash script writing, so creative criticism is welcomed!

Have a look at what you can do with fbcmd, the script could easily be modified to read out notifications etc instead.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...