Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3305090
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:07:51+00:00 2026-05-17T21:07:51+00:00

I have a list of object that, among other bits of data, include a

  • 0

I have a list of object that, among other bits of data, include a date, and I need to create a list of all the objects where that date falls anytime last month, i.e. midnight on the 1st of last month < target data < midnight on the 1st of this month.

I also need the number of total objects that meet this criteria.

Right now, I’m going about it in a series of while loops, but I feel like there has to be a better way, particularly since my script hangs:

        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'])
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:07:51+00:00Added an answer on May 17, 2026 at 9:07 pm

    Instead of get_recent_posts() I would use get_page_list():

    from datetime import datetime, timedelta
    
    this_month_start = datetime.now().date().replace(day=1)
    prev_month_start = (this_month_start - timedelta(days=1)).replace(day=1)
    
    pages = blog.get_page_list()
    last_month_pages = [
      p for p in pages
      if prev_month_start <= p['dateCreated'] < this_month_start]
    last_month_approved_comment_count = sum(
      blog.get_comment_count(page['page_id'])['approved']
      for page in last_month_pages)
    
    print "number of last month's pages:", len(last_month_pages)
    print "number of approved comments for last month's pages:",
    print last_month_approved_comment_count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object that has (among other things) a list of Intents. I
I have an object MainObject with a list of objects, SubObjects, among other things.
I have a list of object that is the data source. Something like that:
I have a list of object that need to be displayed and moveable on
I have a parent object called Page that has a List of objects called
I have an object in a list that I need to rank several different
I have a view that - among other things - contains a list of
If I have an object that among other things is an IEnumerable and I
I have a list of class object that I created as a variable in
I have a list of Object arrays (List) That I am going to pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.