Facebook status notifier

Simple python script which notifies you when a status for a particular person has changed.
It requires the pynotify library along with the Facebook python API.

#!/usr/bin/python

import pynotify
import time 




def desktop_app():
    from facebook import Facebook


    pynotify.init("Facebook_status")

    # need to obtain two md5sums from your own app you create with facebook
    facebook = Facebook("md5","md5")

    facebook.auth.createToken()
    # Show login window
    facebook.login()

    # Login to the window, then press enter
    print 'After logging in, press enter...'
    raw_input()

    facebook.auth.getSession()
        
    dict = {}
    
    while True:
        friends = facebook.friends.get()
        friends = facebook.users.getInfo(friends, ['name', 'status'])

        for friend in friends:
            name=friend['name']
            status=""
            newMsg = False
            
            if 'message' in friend['status']:
                status=friend['status'][unicode("message")]                    
                if dict.has_key(name):
                    if dict.get(name) != status:
                        dict[name]=status
                        newMsg=True
                else:
                    dict[name]=status
                    newMsg = True

                    
                if status != u'' and newMsg == True:
                    n = pynotify.Notification("Facebook", name+" " +status, "gtk.STOCK_INFO")
                    n.set_urgency(pynotify.URGENCY_NORMAL)
                    n.set_timeout(12000)
                    n.show()         
                    

        time.sleep(60)
        print "looped"
    
desktop_app()
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: