他のビットのデータの中でも日付を含むオブジェクトのリストがあり、その日付が先月のいずれかになるすべてのオブジェクトのリストを作成する必要があります。つまり、先月の 1 日の午前 0 時 < ターゲット データ < 午前 0 時今月1日。
この基準を満たすオブジェクトの総数も必要です。
現在、一連の while ループでこれを実行していますが、特にスクリプトがハングするため、もっと良い方法が必要だと感じています。
post = 0 #the current post we're analyzing
posts = 0 #the total number of posts in the month we actually care about
lastmonthposts = [] #I think i can just get rid of this
blog = pyblog.WordPress()
date = blog.get_recent_posts(1 + posts)[0]['dateCreated']
while (date > startthismonth):
print "So far, there have been " + str(posts) + " posts this month we've counted."
post = post + 1
date = blog.get_recent_posts(1 + post)[0]['dateCreated']
while (date > startlastmonth):
print "So far, there have been " + str(posts) + " posts last month we've counted, which is " + str(date.timetuple().tm_mon) + "."
posts = posts + 1
post = post + 1
date = blog.get_recent_posts(1 + post)[0]['dateCreated']
lastmonthposts.append('blog')
for blogpost in lastmonthposts:
postnumber = blogpost['postid']
comments = comments + int(blog.get_comment_count(postnumber)['approved'])