我有一个对象列表,除其他数据位外,还包括一个日期,我需要创建一个该日期在上个月任何时候所在的所有对象的列表,即上个月 1 日的午夜 < 目标数据 < 午夜本月 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'])