I’ve made one of my goals for the year—call it a New Year’s resolution, if you’d like, but of the variety that happens in late-February/early-March—to learn how to program generative texts. I’m hoping that this will eventually lead to longer-form poetry, but I decided at first to start with small, simple projects, like Twitter-bots, as they provide a good opportunity to learn more about the basics of textual processing, while at the same time having a smaller scope than longer-form poetry.
My first Twitter-bot was @tonightiate, a bot that announces random nouns that it’s “eating.” While it works well, the coding was quite sloppy, and a lot of the functionality was “hard-wired” in, quite difficult to expand. With my new bot, I wanted to remedy this, making something that could be expanded in scope with ease.
Subject-matter-wise, I thought it might be interesting to create a bot that reworked the text of a famous author. I’ve been really enjoying Leonardo Flores’s series of essays on Twitter-bots, and wanted to create something along the lines of what I’ve seen there. I decided that the subject of my bot would be Marshall McLuhan. I’d actually meant to make a McLuhan bot a few years back, and created an account—Martial McLuhan—for that reason. Unfortunately, I… uh… just plain forgot how to log into that account. Whoops.
Since I couldn’t log into my old account, I created @massagemcluhan, a bot that would “massage” McLuhan’s quotes—work them over completely, as McLuhan would say. I’ve noticed McLuhan’s penchant for reworking and revisiting phrases (“the medium is the message” and “the medium is the massage” being the most famous), and thought it would be interesting to rework some of these phrases by substituting various nouns into them.
The Python code I developed is as follows (with all my Twitter info redacted):
from random import choice
from random import randint
#set up the OAuth and twitter API
consumer_key = '[redacted]'
consumer_secret = '[redacted]'
key = '[redacted]'
secret = '[redacted]'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth)
#set up variables and seed all the random text arrays
noun = ''
words = [line.strip() for line in open('Nouns(5,449).txt')]
mcluhanquote = [line.strip() for line in open('mcluhanquotes.txt')]
noun = choice(words)
quote = choice(mcluhanquote)
#if the quote starts with a variable, capitalise the variable
if quote == '%':
twitstatus = quote % (noun.capitalize())
twitstatus = quote % (noun)
#tweet the status
As you can see, there’s actually very little that happens here—the majority of the code is actually just setting up the Twitter API. Aside from that, my program draws a random quote from a file and a random noun from another file, then combines the two. The quotes all have one of the nouns replaced with a variable, and look like this:
Let us return to the %s.
The %s is the message.
The medium is the %s.
%s escapes attention as a communication medium just because it has no "content"
It is impossible to understand social and cultural changes without a knowledge of the workings of %s.
%s offers yesterday's answers to today's questions.
I’m hoping to expand this to allow for more complex substitutions/manipulations, but for the time being, this is working well, and I’m rather happy with the results.
In The Medium is the Massage McLuhan (or Quentin Fiore, or Jerome Agel, or someone) writes “When two seemingly disparate elements are imaginatively poised, put in apposition in new and unique ways, startling discoveries often result.” This notion seems to bear out in @massagemcluhan, where a number of genuinely thought-provoking utterances have emerged from this random process. Consider the following tweet:
When I was young, I remember visiting some student archaeologists on summer vacation (we were near an active dig site, and my parents, quite wisely, though we’d find a visit interesting). One thing that stuck with me is the usefulness of garbage: nothing can teach you about a society and culture quite like that which they throw away. A midden heap contains a wealth of information, and is most certainly a communication medium.
I look forward to working with this bot a bit more, as I think it has a lot of room to grow. It’s helpful, too, that the results are so interesting, making it well worth the while. I would love to hear everyone’s thoughts on this, especially comments on the bot itself—this is only my second one, so I have a lot to learn, and I appreciate all the advice I can get..