Digital Writing with Python: Assignment 2

July 13, 2009

Our next assignment in DWP was writing a program that creatively transformed a text using regular expressions. I had been thinking of horoscopes recently and how ludicrously generic those predictions seemed. I wanted to create a program that shuffled random horoscope lines together to generate brand new horoscopes with a snarky tone that was insulting.

First, I captured some random horoscope text off the internet, then wrote a program that grabbed three lines of text randomly, searched for a regular expression to indicate the end of the line, and inserted an epithet. Lastly, I used sys.argv to allow users to enter their sign and have the program print it as a title. The raw text looked something like:

The code I wrote was:

And here are a couple examples of the final output:


You share something with a family member or friend that might cause some strife today -- but you should be able to work it out without coming to blows or storming off in a steaming rage, stupid. You may be able to shake off some karmic baggage, so that's a plus, you pathetic moron. Don't worry too much about whether or not you're getting a good reception from your coworkers or friends -- they are much more in line with your thinking than they are letting on. Keep pushing, you idiot.


It's a great day for you to check in with them, silly. Something seems to click deep inside your mind, and you can understand someone in your life who's been something of a mystery lately, freakshow. You have the empathy they need, you sad little person.


You are in a more thoughtful mood, which might just be perfect for your new circumstances! It's a great time to consider your options and play around with new possibilities, rather than take quick action, silly. You may be able to shake off some karmic baggage, so that's a plus, you douchebag. Try to instill a more playful kind of energy into your workplace or family life today -- it's easy! Some folks may be grouchy, but you can almost certainly get them to see things the right way, you pathetic freak.