Automatically Sorted All-Blogs

OKAY! What I am about to say proves the fact that given 24 hours, P-Sharma can do ANYTHING!

Okay so since last night, I’ve been writing this script that AUTOMATICALLY SORTS the blogs on ALL BLOGS. I know I know … you want details.

What it does is this … IT LOOKS AT EVERY WEBLOG (THE ATOM AND RDF FEEDS) AND FIGURES OUT WHEN THE LAST POST WAS POSTED. IT THEN SORTS THE WEBLOGS ON ALL BLOGS BASED ON THESE DATES.

The weblog with the most recent entry gets bumped to the top automatically. Therefore, you only read what is important. All those lazy asses can keep sitting at the bottom. Just read what is the most recent!

What is the drawback? The only drawback is the processing time. It takes roughly 5 -7 seconds for the entire process to finish. This is IN-ADDITION to whatever time it took earlier. Think of it this way … 5 seconds waited is 5 minutes saved!

What if you liked the old one? Well … Old one is still available at http://www.pranavsharma.com/allblogs/old

So HOW Exactly did I do it? This is going to get a bit technical … So I wrote the script ALL by hand and from scratch. I wrote this in PHP. I located the ATOM feeds on the SquareSpace blogs and the RDF feeds on Gokul’s and mine websites. Then I opened a read-only filestream to these feeds. Then I formed an appropriate search criteria and located the date of the latest post and stored it in a string variable

Next, I converted that string variable to a UNIX timestamp. After that, I combined these timestamps with the URLs of the respective weblogs and put it all in a 2-D array. Then, as per Karthik’s recommendation, I used a BUBBLE SORT to sort the dates in descending order. Lastly, I printed the URLs in the sorted order and used these URL’s to create inline FRAMES just like the old ALL BLOGS script.

I know I am excited about this but my excitement doesn’t mean as much as convenience for you guys. I don’t want to turn this into another Chat-Script that is more annoying than useful. So if the verdict from you guys is that you like the OLD one better then the OLD one it will be. I give you 10 days to BETA-TEST.

UPDATE: Here is the Code I used. If you plan to reuse this code then please replace ALL ‘«’ with ‘<' and ALL '»' with '>‘ and I do mean ALL (even the ones in the array declaration).

«html»
«script language=”php”»

//MAIN array that will be sorted based on latest post date
//5 fields: Time Stamp, URL of the blog, URL of the ATOM/RDF feed,
//Tag before timestamp to search for, and, Time Adjustment factor.
$array = array (
0 =» array (”time” =» 1087816162, “URL” =» “http://ambar1.squarespace.com”, “feed” =» “http://ambar1.squarespace.com/display/GetATOMFeed?moduleId=23465″, “tag” =» “«created»”, “adjustment” =» 0),

1 =» array (”time” =» 1087816162, “URL” =» “http://mukta.squarespace.com”, “feed” =» “http://mukta.squarespace.com/display/GetATOMFeed?moduleId=22534″, “tag” =» “«created»”, “adjustment” =» 0),

2 =» array (”time” =» 1087816162, “URL” =» “http://www.gocool.org”, “feed” =» “http://www.gocool.org/index.rdf”, “tag” =» “«dc:date»”, “adjustment” =» 28800),

3 =» array (”time” =» 1087816162, “URL” =» “http://www.pranavsharma.com”, “feed” =» “http://www.pranavsharma.com/index.rdf”, “tag” =» “«dc:date»”, “adjustment” =» 18000),

4 =» array (”time” =» 1087816162, “URL” =» “http://ankan.squarespace.com”, “feed” =» “http://ankan.squarespace.com/display/GetATOMFeed?moduleId=22359″, “tag” =» “«created»”, “adjustment” =» 0),

5 =» array (”time” =» 1087816162, “URL” =» “http://vish.squarespace.com”, “feed” =» “http://vish.squarespace.com/display/GetATOMFeed?moduleId=22651″, “tag” =» “«created»”, “adjustment” =» 0),

6 =» array (”time” =» 1087816162, “URL” =» “http://anu.squarespace.com”, “feed” =» “http://anu.squarespace.com/display/GetATOMFeed?moduleId=22734″, “tag” =» “«created»”, “adjustment” =» 0),

7 =» array (”time” =» 1087816162, “URL” =» “http://divs.squarespace.com”, “feed” =» “http://divs.squarespace.com/display/GetATOMFeed?moduleId=22371″, “tag” =» “«created»”, “adjustment” =» 0),

8 =» array (”time” =» 1087816162, “URL” =» “http://suewije.squarespace.com”, “feed” =» “http://suewije.squarespace.com/display/GetATOMFeed?moduleId=22630″, “tag” =» “«created»”, “adjustment” =» 0),

9 =» array (”time” =» 1087816162, “URL” =» “http://www.squarespace.com”, “feed” =» “http://www.squarespace.com”, “tag” =» “«created»”, “adjustment” =» 0)
);

//*********************************************
//ACCESSING LATEST POST DATES for known blogs
for ($i=0; $i«9; $i++){
$fs = fopen($array[$i][”feed”], ‘r’);
if ($fs) {
$tag = “initialcharacter”;
$subtag = substr ($tag, 0, 9);
while ($subtag !== $array[$i][”tag”]) {
$tag = fgets ($fs, 99);
$tag = trim ($tag);
$subtag = substr ($tag, 0, 9);
}}

$date = substr ($tag, 9, 19);
$array[$i][”time”] = (strtotime($date) + $array[$i][”adjustment”]);
fclose($fs);
}
//finished accessing latest dates from all blogs
//************************************************

//commencing BUBBLE-SORT
for ($i=0; $i«9; $i++) {
$array[9] = $array[$i];
$biggest = $i;

for ($j=$i; $j«9; $j++) {
if ($array[$j][”time”] » $array[$biggest][”time”])
$biggest = $j;
}

$array[$i] = $array[$biggest];
$array[$biggest] = $array[9];
}
//End BUBBLE-SORT
//USED $array[9] as a temporary swapping mechanism
//************************************************

//Begin Printing
echo “\n«head»\n\n”;
echo “«title»All blogs - Automatically Sorted«/title»\n”;
echo “«/head»\n”;
echo “«div align=center»\n”;

for ($i=0; $i«9; $i++) {
echo “«iframe src=\”" . $array[$i][”URL”] . “\” frameborder=0 scrolling=\”yes\” width=97% height=500»«/iframe»\n”;
echo “«br»«br»«hr»«br»\n”;
}

echo “«/div»\n\n”;
//END PRINTING
//***********************************************

«/script»
«/html»

19 Responses to “Automatically Sorted All-Blogs”

  1. Karthik Says:

    BTW, I did not recommend bubble sort, I just said that for a number like 7, even bubble sort will not take that much time. Just saying…Anyway, this sounds awesome dude, keep up the good work.

  2. Karthik Says:

    BTW, if the sorting takes time, you should probably do a sort that is quicker…

  3. Kaushik Says:

    Pranav - I am impressed :). You have inspired me to look into RSS-aggregators and start using one. Have you implemented RSS feeds for your blog? The new ‘All Blogs’ is great :).

  4. Kaushik Says:

    Pannu, work on your picture album next… I am sure there are better ones out there. I’ll look around too, and ping you if I find any good ones.

  5. Pranav Says:

    Karthik - It is not the sort that takes long. It is the process of accessing each page and reading it that takes so long. I don’t think it really matters what type of Sort I use.

    Kaushik - All of the Blogs here have RSS feeds available including Gokul and Me. It is just the fact that nobody is really aware of this truth. I would highly recommend RSS Aggregators … they are great! I don’t use one myself as you can see, I just tried to write one! (Not exactly but oh well)

  6. Ankan Says:

    and all this time I thought you sucked at programming.

    Anyways…only a true nerd would put programming code on his/her weblog.

  7. Pranav Says:

    Ankan - Whatever man! I only code for the good. At least I don’t code like you 40 hours a week. I only code once in a blue moon and that too only to solve a problem. So I think ppl like you who code for a living would categorize as “a nerd”.

  8. divs Says:

    wow pranav.. this is awesome!!

  9. Anu Says:

    damn…this really doesnt make sense to me…but looks great and sounds great!!!

  10. ritu Says:

    no pranav–trust me, you are the true nerd. :)

  11. Vish Says:

    Pannu, i agree with them that u are a true nerd, and now we knwo why you cant decide between business and CS.

  12. gok Says:

    Pranav- Good job. I like the idea. But honestly, I’d much rather see the post headers (via RSS feeds) instead of the webpage itself. I know my RSS feed can do that, and that you’ll require some XML parser. But I haven’t done much research here. Perhaps there’s something you can figure out ?

  13. gok Says:

    And besides, there should be pre-existing scripts available for this kind of stuff right? Almost every weblog I go to has something about (the latest posts by … )

  14. Pranav Says:

    Fixed the little bug that came about due to differences in time zones. What happened was that Squarespace records time in GMT whereas pranavsharma records in Eastern time and Gocool records time in Pacific time. I added an adjustment factor to time comparisons.

    I changed the code I posted earlier … made it a lot cleaner. I just added variations in reading to the array.

  15. :DIA Says:

    Hey - 2 special requests… 1. can you start a new post (ASAL contd.) so ppl like me don’t keep scrolling and scrolling and missing the end of this post everytime.
    2. How about an additional sorting factor based on popularity - the more the number of incoming comments - the higher up the blog :)

  16. Kaushik Says:

    I dont think the number of comments should be used as a criterion. Honestly, do most of you post a comment everytime a post hits home?

  17. Karthik Says:

    Well, one more thing about number of comments. People might “jack up” their comment hits (like bots) to increase their popularity rating!

  18. Pranav Says:

    Dia, first I agree with Kathik a lot and second, when choosing between ‘most recent entry’ and ‘most comments’, i think the former takes the prize.

    Lastly, I tried, but I was unable to have a computer figure out how many comments each entry had - a technical road block.

    So, I think we might have to learn to accept the current system of sorting.

  19. Pranav Says:

    Kaushik - that’s just true for you and a select few that work at “whatever your company is called”