Slow Python Script and Using Pipenv with AWS Lambda
I’m working on improving a python script I wrote to get a list of old posts from a wordpress website. Basically I want to be able to see what post I wrote X years ago on this day for any wordpress site.
This script uses the wonderful requests library and the very powerful public Wordpress API.
I am also using pipenv for the first time and its wonderful. I wish I started using this tool years ago.
What it Does Right Now
- Takes a dictionary of sites and iterates over each one
- Prints out to the console
print("1 year ago I wrote about {0} {1}".format(p['title']['rendered'], p['link']))
if years_ago > 1:
print("{0} years ago I wrote about {1} {2}".format(years_ago, p['title']['rendered'], p['link']))
The Script is Super Slow
You can time how long a script takes on OS X using thetime command.
Levs-iMac:OldPosts levlaz$ time python old_posts.py
1 year ago I wrote about Thoughts on “Sacramento Renaissance” https://tralev.net/thoughts-on-sacramento-renaissance/
real 0m11.192s
user 0m0.589s
sys 0m0.060s
Plans for Optimization
- Use Redis (or something) to cache the results.
- Get rid of some of the for loops if we can.
Plans for Usage
- Deploy to AWS (Labmda?)
- Have this run on a Cron Job every day (using CloudWatch)
Plans for Additional Features
I want to share all of the posts from that day on social media. Instead of plugging in all of the various accounts that I need I am planning on using the Buffer API to post everywhere at once and queue up posts so that it does not fire off a bunch of stuff at the same time in the event that there are many posts for that day.This will involve doing some sort of Outh dance because I don’t think that Buffer offers using personal access tokens.
I'll Just Use Lambda
Famous last words.It’s not the worst thing in the world, but when you are using the amazing pipenv tool you have to go track down where the site-packages are located and zip them up in order to ship your code to AWS Lambda.
Unsurprisingly someone opened a feature request for this, but the solution in the comments works just fine.
I wrote a little bash script that is being called through a Makefile to zip up the site-packages along with the core python code in preparation to ship it off to AWS Lambda.
Bash Script to Zip Up Site-Packages
Makefile
.PHONY: package
package:
sh package.sh
Thank you for reading! Share your thoughts with me on bluesky, mastodon, or via email.
Check out some more stuff to read down below.
Most popular posts this month
- 2025 Reading Log
- 3 packs
- Growing the CircleCI Community with Discourse
- My Custom Miniflux CSS Theme
- Sacramento Then and Now
Recent Favorite Blog Posts
This is a collection of the last 8 posts that I bookmarked.
- Grow, Like a Tree Not a Cancer from Jim Nielsen’s Blog
- Pluralistic: All the books I reviewed in 2025 (02 Dec 2025) from Pluralistic: Daily links from Cory Doctorow
- DEP-18: A proposal for Git-based collaboration in Debian from Optimized by Otto
- [RIDGELINE] No Phones in The Ten-don Shop from Craig Mod — Writer + Photographer
- My next chapter with Mastodon from Mastodon Blog
- How many pillars of observability can you fit on the head of a pin? from charity.wtf
- The Software Essays that Shaped Me from Refactoring English
- Give Your Spouse the Gift of a Couple's Email Domain from mtlynch.io
Articles from blogs I follow around the net
Pluralistic: A year in illustration (2025 edition) (03 Dec 2025)
Today's links A year in illustration (2025 edition): I think I'm getting the hang of this? Hey look at this: Delights to delectate. Object permanence: HADOPI is born; Tea Party wants to disenfranchise renters; How to kill TPP; Mozilla ejects Thund…
via Pluralistic: Daily links from Cory Doctorow December 3, 2025Hank Green And The Fantastical Tales of God AIs
Hank Green And The Fantastical Tales of God AIs AI Doomerism is a Decoy: Yet the supposed AI apocalypse remains science fiction. “A fantastical, adrenalizing ghost story is being used to hijack attention around what is the problem that regulation needs to s…
via notebook from jason December 3, 2025On the Move
Mike Peel; Jodrell Bank Centre for Astrophysics, University of Manchester The Lovell Radio Telescope at Jodrell Bank Observatory, near Goostrey, Cheshire, England. If you ever feel like you are constantly on the move, that’s because you are. And not only in…
via Brian Koberlein December 3, 2025Generated by openring