AesopFableBot — My 1st Python 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!

--

--

--

he/him. having fun with my friends in cyberspace

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How We Scaled Our Marketplace Systems

Tutorial Fuzzy Logic Mamdani for Arduino

Tutorial Fuzzy Logic Mamdani for Arduino

How to Share The PyCharm Project on Github

Three Program Templates for Working with Arrays, Lists, or Vectors

Tutorial Fuzzy Logic Mamdani for Arduino

Tutorial Fuzzy Logic Mamdani for Arduino

Tutorial ESP32 Door Lock 3in1 Fingerprint Keypad 4x3 and RFID PN532

Tutorial ESP32 Door Lock 3in1 Fingerprint Keypad 4x3 and RFID PN532

Windows Desktop VR

The Julia Challenge in C++

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Liam A. Trotzuk

Liam A. Trotzuk

he/him. having fun with my friends in cyberspace

More from Medium

Python program to convert the temperature in degree centigrade to Fahrenheit

degree to fahrenheit ,centigrade fahrenheit conversion ,python program to convert celsius to fahrenheit

Develop Your Weather Application with Python in Less Than 10 Lines

Automatically Copy the Output of a Python Program Easily

Web Scraping using snscrpe