from sqlobject import *

conn = connectionForURI("mysql://root:@127.0.0.1:3306/benmurwp")
sqlhub.processConnection = conn

class Comment(SQLObject):
	class sqlmeta:
		fromDatabase = True
		table = "wp_comments"
		idName = "comment_ID"

class Post(SQLObject):
	class sqlmeta:
		fromDatabase = True
		table = "wp_posts"
		idName = "ID"

for post in Post.select():
	comments = Comment.selectBy(commentPostID=post.id, commentApproved="1")

	if post.commentCount != comments.count():
		print "Post", post.id, "has wrong comment count, fixing up"
		post.commentCount = comments.count()

