Weekly Ensight: Clean up on WordPress aisle 6

Mackenna Dsouza
2 min readJan 26, 2021
Weekly Ensight : Clean up on Wordpress aisle 6

Analysts, 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 XML-RPC library to
- instantiate a WordPress client using the blog URL, username, and password configured within Energiewerks Ensights
- 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.
- 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 )
- Energiewerks Ensights then iteratively gets 1000 media items using the rpc call GetMediaLibrary on the media object.

--

--

Mackenna Dsouza

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