An analyst, using Energiewerks Ensights integrated with the WordPress blogging platform, to disseminate fundamental analysis reports and studies over the last couple of years, wanted to delete the stale posts and associated media attached to the post to free up space on the blog.

In total there were 18k+ posts and about 92k+ media items ( png, pdf, jpg, xls) files that needed to be deleted from the blog.

Using the Energiewerks Ensights toolkit, this was accomplished using the following python code snippet.

from utils.WordpressUtilities import WordPressUtilities
from datetime import datetime,  timedelta

if __name__ == '__main__':
    wp = WordPressUtilities()
    wp.configure()
    wp.deleteBlogPostsOlderThanDate(datetime.now() - timedelta(days=30))
    wp.deleteMediaItemsOlderThanDate(datetime.now() - timedelta(days=30))

Under the covers, Energiewerks Ensights uses the python wordpress xmlrpc library to

  1. instantiate a WordPress client using the blog URL, username, and password configured within Energiewerks Ensights
  2. then uses the client rpc call GetPosts providing a dictionary of parameters that contains two parameters – increment and offset, to retrieve a set of blog posts.
  3. iterates through the set of blog posts and delete blog posts that meet the date criteria specified ( in this case anything of 30 days or more vintage )
  4. Energiewerks Ensights then iteratively gets 1000 media items using the rpc call GetMediaLibrary on the media object.
  5. Iterates through the 1000 media items returned at a time, selects media items that meet the date criterion and subsequently the category of items from the composite name of the item, and delete the media item from the blog.

Energiewerks Ensights provides simple yet powerful tools to simplify day to day activities of fundamental analysts on the energy, commodity, equity, currency, and equity trading desks of some of the largest trading firms globally.

Idea Guy | Entrepreneur | Angel Investor | Technologist | Quantitative and Fundamental analyst

%d bloggers like this: