Thursday, February 03, 2005

Counting the number of blogs in a click

"The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. - Ezekiel 25:17."

Just as the blog world is crippled by the inefficiences of blogger, one man stands tall amidst ruins to hold the brewing-coffee for the rest of them to bask in bliss. One man - hitting theaters soon!

Please find below a code snippet that will help you find how many blogs you have written so far.

What you have to do.

1. Go to the edit posts page in blogger and copy the whole list of blogs that is listed there.
2. Save it in a simple text file.
3. Find a Java IDE or any machine that has java installed.
4. copy the code below into the java file titled BlogCounter.java and set the file's location correctly in the code.
5. run it and you will be told how many blogs you have written so far.

/*
* Created on Feb 3, 2005
*
* Author: Rathish Balakrishnan
*/
package com.sap.cbs.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class BlogCounter {

public static void main(String[] args) {

String path = "C:/blogs.txt";
String magicSuffix = "View Delete";
try {
FileReader reader = new FileReader(new File(path));
BufferedReader bw = new BufferedReader(reader);
String line = null;
int noOfBlogs = 0;
while ((line = bw.readLine()) != null) {
if (line.endsWith(magicSuffix))
noOfBlogs++;
}
System.out.println("The number of blogs you have written so far : " + noOfBlogs);
} catch (Exception caught) {
System.out.println("Please make sure you have specified the correct file location");
}
} // end of method
} // end of class

Hope this helps.

PS: Just realized that the editor kills all tabs making my code look like my first CP1 program. More seriously, the tab between "View" and "Delete" in my "magicSuffix" variable is lost. Fear not, all you have to do is to copy it from the text file yourself and replace it in the variable.

5 Comments:

Blogger Sagnik Nandy said...

Rathish boy - a pleasure to see a "code" of conduct on your page - aha.

Well I tried a similar thing once but gathered that at least for me Blogger shows only a max of 300 posts in the edit window. So what I did was a bad hack. Blogger allows me to post the entire blog on one page. So I did that for a while and parsed that page for "posted by" and took the count coz they don't have a limitation (or maybe it is 999) on the nuber of posts that appears on the front page. If there is anyway of removing the 300 limitation lemme know.

11:47 PM  
Blogger ledsuki said...

I still remember that 'look' you had, after we'd finished watching 'Pulp Fiction' at Beranger. :)...

9:01 AM  
Blogger Rathish said...

@Sagnik - aaha! Even 300 is way beyond my tested test-cases (But boy, am I glad you write so much and so well!) :) Anyways, shall definitely look around to see if there's any work around.

@Suki - :)) I am sure you do! I have gained a deeper understanding by seeing it many more times since then!

9:31 AM  
Blogger Sagnik Nandy said...

thank you, thank you :)

10:07 AM  
Blogger Kumari said...

And there is also ME , selecting 'show 100 posts' in my 'Edit Posts' section and counting them 1..2..3 - till i reached that Sixty :(
Now you know why i insist i am in the wrong profession :p:p

1:56 PM  

Post a Comment

<< Home