Python Community Server: Development

A weblog about programming in Python, C#, Java, Perl and C++ - and the occasional comment on PyCS development
new: discuss community servers on the CommunityServerWiki!

1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

[ Aug ] [ Oct ]

the locals
also available in XML
Copyright (c) 2002 Phillip Pearson
spread the dot


*more* uses for xmlStorageSystem

Dean Goodmanson is really getting into this whole 'uses for xmlStorageSystem' game ;-)

Comment on this post [ so far]

Radio comment hackery explained

One of the most widely-used but least well understood features of RCS is the javascript comment count. Basically, when someone accesses your weblog, their browser also downloads a bit of javascript that generates the coment counts (so you can let people know that posts have comments, rather than having to go through everything by trial and error). This is the key to how the Radio weblog comment generator works.

For example, here are John Robb's comment counts:

Not the easiest format to parse, you may think, but there's actually nothing to it. All the info we need is in the postids = [...] and counts = [...] bits. In Python, two regular expressions will get you all that:

    postids, counts = [
        re.findall( r'\"(.*?)\"', block )
        for block in re.findall( r'\[(.*?)\]', text )[:2]

Aside: re.findall( regex, string ) will find all matches to regex in string. So re.findall( r'\d', 'abcd123 ... 4 5 6' ) will return [ '1', '2', '3', '4', '5', '6' ].

Now we put that data together (to get one hash table of comment counts, indexed by comment ID):

    details = dict( [ ( postids[i], counts[i] ) for i in range( len( postids ) ) if postids[i] ] )

The dict() function makes a hash table ('dictionary') out of a list of key:value pairs (tuples). dict( [ (1, 2), (3, 4) ] ) = { 1: 2, 3: 4 }. The above code iterates over postids and counts and makes a list of id:count pairs, then turns that into a dictionary.

Once we've got the data in this format, we can do what we like. The simplest way to make an RSS feed is to sort the post ids into reverse order and dump them out in the appropriate format (I won't write the RSS here because it's fairly long winded):

    ids = details.keys()
    for key in ids:
        print "post %s: %s comments" % ( key, details[key] )

We could stop here, however this is going to generate an RSS feed that will get longer and longer as more comments are posted, so we want to truncate it a bit and only show the most recently changed comment counts.

To do this, we save the details dictionary to a file. Whenever we check for new comments, we read this file and see what has changed, and when new comments do appear, we write the updated details dictionary to the file. We also make a list that tracks the most recent n changes (I use n = 20) and only displays them in the RSS feed.

    See this code at work

Comment on this post [ so far]

New comment monitor seems to work

Lots of talk about comments right now:

- Dave Winer
- Sam Ruby
- Blogging Alone

One good way to keep track of comments on somebody's weblog is if they have an RSS feed for them. phpStorageSystem does this out of the box, but PyCS and RCS don't.

However, they all provide info on your comments; this is required so your blog can display a comment count next to each item. I've written something that will keep track of those counts and produce an RSS feed of the 20 most recently-changed comments.

        Comment Tracker

Give it a go. It seems to work fine for me. I'll move it over to a faster web server once a few people have tried it out. This should solve the problem of keeping track of comments on a Radio weblog.

Comment on this post [ so far]