2009
09.11

Hello once again, so to increase my exposure I let Facebook import my blog and add it to my notes section and this is working out very well. My visits to the site have been on the rise since I refreshed Philtopia last month and I tend to get lots of comments.

But we have a problem!

When people comment in Facebook it doesn’t end up here on WordPress. So I have some comments here and some there when if combined I could have lots of comments here! (here being WP). Of course I could just manually add the comments like some kind of sucker but fuck that!

Facebook comments plugin

Now so far with WordPress anything I have searched for I have received and this was no different. I typed Facebook notes into the plugin search and Facebook comments comes right up and of course I’m just like “Shwing!”. I install the plugin and am expecting the instant gratification I have received with every other plugin I have installed yet I get nothing. What the hell I say and begin the hunt for the problem.

The Problem

Unfortunately while this plugin was working great up until 6 months ago it breaks any time Facebook changes something so while I commend the effort on the several people who had made it and fixed it over and over again it broke in March and it stayed that way. I figured ok I can fix it and dove into the source, however it uses a bunch of complicated matrix like regexp to interpret every line of the HTML file which explains why it can break so damn easy.

Idea

I had written a tracker that records the users online from Vendetta online and saves them to a database that I use for a sort of ingame !seen feature last year and instead of trying to interpret the website I tag the data I want with % (Don’t know why I chose % but it can’t be used in a character name and it works) then I strip_tags the entire data and parse out what I want. Much easier to handle the data once all the crappy XHTML is out of the way. Anyways that works like a charm and there are thousands of user characters logged thanks to that.

Back to this situation though. So anyways  decided to try something similar with Facebook notes to extract the comments and their creators.

First task

First I found specific code that only occurs before and after what I want. Yes I am aware that when Facebook changes it will break again but! it is much easier to change the tag I’m marking then rewrite a massive regexp to detect different code so getting this up again after an update will be easier.

This is completed

Second Task

Separate what I want with tags. Also done with some simple str_replace and in one instance where I had to confensate for a variable Div tag id I used a preg_replace.

This is completed

Third task

Get rid of all the code and in turn create something simpler to parse out

It generates output kinda like this:

%title%Snow Leopard rocks!%
Share Saturday, August 29, 2009 at 12:31am | Delete

I just installed Snow Leopard onto my machine and I must say it is pretty freakin sweet. Sure it doesn’t have zilions of new ways to do things like the upgrade from Tiger to Leopard but the little things it improves upon are fantastic. Time machine Remember that preparing thing that took for damn ever? Well I hooked up my external to my Snow Leopard install and since it was an entire new OS was expecting preparing for at least an hour instead what I got was Calculating backup with a % of how far along it was. Can anyone say Hell yes! Finder Finder window looks the same but the menus are nicer looking. Not to mention when I do a multi file copy it doesn’t get all slow anymore. Stacks I have since Leopard always kept applications as a stack and there was always one little annoyance. Say you had an application in a folder or if you wanted to click utilities it would open a Finder window outside of stacks…kinda pesky eh? Well Much to my surprise when I first clicked applications was that first I can scroll in a stack with my trackpad and second when opening a folder it opens it in the stack window! w00t! Anyways I’m just so excited from just a few minutes with the OS that I had to talk about it. I’m sure there is a lot more I’m missing but first impressions count and my first impression is very good with this one!
Updated about a week ago · Comment · Like / Unlike · View Original PostView all 10 comments
%person%Phil Spencer%
%comment%yea probably. i wouldn’t worry about it, if activity monitor is showing intel 64bit for most things then you’re fine.%August 31 at 10:58am · Delete
%person%Jason Maiuri%
%comment%good point Phil you are the man Thanks%August 31 at 11:17am · DeleteWrite a comment…

Don’t worry I am going to change the token from % to something I’m very unlikely to type like a heart or diamond or something but at the moment it is very early in the mission!

Fourth task

Parse all that data. This was fun only took 42 lines of code, probably 8 of that is } and //comments and it does something different based on whether it’s a title, comment author or comment

The parser just parsers and shows me the data at the moment but this marks the end of part 1 of my mission. Part 2 is to use CURL to connect to Facebook and actually fetch a live copy of the html because right now I am just using a saved html file I update every day. Part 3 of course is to actually save the data into the WordPress comments database.

Sample Output:

Article: How sweet it is
Author: Sandra Lynn Glover
Comment: Who would have thought you’d go all Apple!

Author: Phil Spencer
Comment: It is so easy!

Author: David MacLaren
Comment: That’s great! Thanks for the update.

Anyways This concludes part 1 of my mission stay tuned for future updates! Unless of course you don’t give a shit about this but if you have bothered to read along this far that isn’t my problem! 😉

Facebook Comments

No Comment.

Add Your Comment

You must be logged in to post a comment.