Facebook Notifications

Yesterday, I set up an account with Facebook. I'm not especially fond of the service, but my girlfriend's abroad, with metered internet, and wants to send me pictures. Facebook lets her upload once, and share many times. I'm also under pressure from other organizations to have a profile there. So I caved and set it up.

One of my fears of the service is spending too much time there, or going often to check that I haven't missed any important messages. I know that there are clients for Macintosh that will pull Facebook notifications to the desktop, but couldn't find a parallel for Linux. There are a few clients, but they're either processing-heavy or just broken.

The most promising approach I saw online scraped Facebook's RSS feed for events, and displayed them. I implemented it using a mix of modules.

First, a FancyURLOpener grabs the RSS feed. The subclass URLReader simply overrides the useragent string, so that I'm not identified as a bot. Bots aren't treated well on the internet.

Second, BeautifulSoup, an HTML parsing library, finds all of the items in the feed, and scrapes their description to form a list of notifications.

Third, the script opens the last message it's notified you about (that's stored in a config file), and truncates the list to exclude all notifications you've already seen.

Finally, pynotify is used to send out FreeDesktop notifications. These should work under any desktop environment, as long as there's a notification server.

To use the script, you need to give it two pieces of information: the URL to your RSS feed, and a file to store the most recent notification. To find a URL for the RSS feed, go to Facebook, click on Notifications, then See All. Just under Your Notifications, Facebook lets you get notifications by SMS or RSS. Click on RSS, and copy the text of that link into the URL variable near the top of the script. Set the CONFIG variable to some empty, writable file. (I'd suggest "/home/$USER/.config/fbnotify" or something similar. I'm not sure if Python can read Bash variables or expand the ~, so if you have issues, use a fully qualified path.)

Everything in the script is simple and well-commented, so feel free to hack away!

Cheers!