AesopFableBot – A Twitter Bot

Twitter link: https://twitter.com/AesopFableBot
Github link: https://github.com/liamtrotzuk/aesop-twitter-bot/blob/master/main.py

Having been on Twitter for a few months and having greatly enjoyed the ability to enjoy classic literature tweeted by bots like SapphoBot, which reads fragments of Sappho’s poetry, or MobyDickatSea, which reads random lines from Moby Dick (among many other bots that read many other works of literature and many other writers), I finally decided to make my own literature bot. At the time of conception, I had been exploring some of the more obscure tales by Aesop, and decided that his hundreds of fables were a good candidate for a bot to tweet out at a certain cadence.

I constructed the bot in Python. I scraped the underlying fables — translated from Ancient Greek into English by George Fyler Townsend — from a Project Gutenberg webpage using Beautiful Soup.

Twitter access was obtained via Tweepy, which grants easy-to-use access to the Twitter API with credentials obtained via Twitter’s Developer Access.

Fables were broken down into their titles — the initial tweet — and then strings of complete sentences (delineated by periods) such that the total number of characters in each string of sentences did not exceed 280. In the rare instance that a single sentence exceeded 280 characters, each sentence was broken down into strings of complete clauses (delineated by commas) such that the total number of characters in each string of clauses did not exceed 280.

The task turned out to have a few unexpected quirks.

Quirk 1: certain fables (no apparent rhyme or reason as to which) had a secondary paragraph — the punchy ‘moral’ that is explicitly stated at the end of some fables, i.e. ‘slow and steady wins the race’ for The Tortoise & the Hare — that was an entirely separate <p> BeautifulSoup object, requiring an additional step in the loop.

Quirk 2: 3 of the 311 total fables on Project Gutenberg used a word that used to be a synonym for ‘bundle’ but has since become an offensive term for LGBTQ folks. Even with the accompanying context for the word in each fable, I thought it best to change every instance of the word to ‘bundle’ in order to avoid any needless confusion or hurt.

Quirk 3: strange formatting for one of the fables rendered a textual line from a fable paragraph as an <h2> line, which meant that my script would interpret it as a fable title. The error would only occur 1/311 days, but it would still look ugly. I told the bot to ignore that particular line by exempting all objects of text containing the word ‘grievances’, which is a word that only appears in that single misformatted line.

The script was hosted on a free Google Cloud Virtual Machine running Linux, with the bot’s Python script scheduled to run at 1 PM EST every day. Feel free to follow at the above Twitter link if you’re interested in a daily dose of Ancient Greek morality dispensed by talking animal characters!