Need Help Implementing Python Stats Script

So, while everyone is busy bickering about why they’re leaving DreamHost, I’m busy working on my site because I’m staying. I’d love to talk about that, but it would just be pointless. Some people are just set in their ways and beliefs that something better exists, and that you can find shared hosting with the features, uptime, and support of a dedicated server. That just doesn’t happen in the real world. But, enjoy your Golden Calf.

Anywho, would anyone happen to know how to implement this Python script for displaying RSS stats with a WordPress blog? Or, just get it to work in general?

I’ll take a look at it.


Thanks Robert!

Okay, I’ve got it working from the command line, which is hopefully most of the battle.

Problem #1 is that Rui used a Python feature (using the in operator with dictionaries) that is not available in the version of Python that DreamHost has installed. It’s not too hard to install and compile Python yourself, fortunately. I have Python 2.4 installed, and that works.

Problem #2 is that you need to supply the correct path to the Apache access log.

Problem #3 is that you need to supply the right regular expression to find HTTP requests for your rss or atom feed.

Problem #4 is that if there are no accesses to those feeds in the current access.log, you will get a division by 0 error. Since the access logs are rolled over, if you run the script right after the log is rolled over and you have an empty or virtually access.log file, you might see this.

For problem # 1, you need to install a newer version of Python. Let me know if you need help with this. I haven’t written up those instructions, yet, in a form that would be useful to you.

For problems #2 and #3, change the last couple lines of code to:

if __name__ == '__main__': username = "atacama" domain = "" path = "/home/" + username + "/logs/" + domain + "/http/" feedregex = "/feed/(rss2|atom)/" o = LogAnalyzer(path + "access.log", feedregex) o.dump() and then change the username and domain variable values appropriately. The regular expression above (feedregex) will work if you installed your WordPress blog in the root directory. I can whip up a more flexible one later, but it’s getting late tonight.

For problem #4, change the following line in dump

self.table['Others']['percent'] = self.table['Others']['count'] * 1.0 / self.count to

if self.count == 0: self.table['Others']['percent'] = 0 else: self.table['Others']['percent'] = self.table['Others']['count'] * 1.0 / self.count Robert

Hm, this is a little bit over my head. And, with all the stuff I have going on right now, I don’t think I’ll have time to install Python, etc. Thanks anyway, that was very generous of you.

“Problem #1 is that Rui used a Python feature (using the in operator with dictionaries) that is not available”

This feature is available in Python 2.2; I this version is accessible by using python2.2 from the command line. Otherwise, change the code to call has_key instead, which might be easier than compiling Python

No problem. I hadn’t hacked on any Python code in a while, so it was a fun diversion.

Larry, thanks for the info on has_key. I should have thought to try that. It was late and I already had 2.4 installed, so expediency ruled.

I had forgotten that DreamHost also has Python 2.2.1 installed. FYI, for anyone else, if you type python, you will get a Python 2.1.3 interpreter (at least, as of today). To get Python 2.2.1, you have to type python2.2. In a Python CGI script, that means setting the first line to:


MacManX, if I get a chance, I will hack on it some more and try to get it to produce some output that can be formatted nicely on a page with CSS. I’ll let you know how it goes.


Well…in case you want a version in Perl…

Couldn’t get the inheritance to work.

:cool: Perl / MySQL / HTML+CSS