A few months ago I tweeted this absolutely true statement.
Confession time: my secret subversive goal is drowning the internet in as much anime artwork as possible. Programming and blogging are just fronts for this.— Max Antonucci (@Maxwell_Dev) April 22, 2019
Over the last year my anime-related side projects fueling this plot have grown in scope:
- Scraping an anime image database to email me several each morning.
- Linking this scraped data to a custom API endpoint to show random images.
- Using this API endpoint to make an anime quote image maker.
The next roll I've taken down this slippery slope now includes:
- Create a bot that shares random anime quote images on Twitter all day long.
Last week this vision finally moved from delusion to reality, and the @AnimeQuoteImage bot was born! Yes, I'm now using robots to fuel my anime addiction.
To celebrate this latest step on my path to the nerd asylum, I wanted to share the basics of how it works and my favorites of its work so far.
How the Bot Works #
If you want to look over the actual code, you can check out the open-source repo with the bot's code.
The bot uses Puppeteer to open my Anime Quote Maker in a headless Chrome browser. It's programmed to start with a random image, a random quote, and randomly style the quote from what's available (color schemes, filters, alignment, etc).
Puppeteer sizes the browser in a 700 by 700 pixel window, which makes the random quote fill it just right, and takes a screenshot. It also grabs the quote's text and author from the DOM.
Node passes this info to Twit, a popular Node add-on for using the Twitter API. It composes a tweet with the image, quote, and author, and sends it off.
This all goes to Heroku, which uses the Heroku Scheduler add-on to rerun all these steps every 30 minutes.
I hit turbulence getting all the Puppeteer dependencies uploaded, but after that there were few issues and the Twitter bot was born!
My Bot's Favorite Work So Far #
I'll start with some positive examples of quotes, images, and styling that somehow came together almost perfectly.
"There is an interest in that which is hidden and which the visible does not show us."— Anime Quote Image Bot (@AnimeQuoteImage) July 3, 2019
~ Rene Magritte pic.twitter.com/xX8U0hSMCn
"Only those who dare to fail greatly can ever achieve greatly."— Anime Quote Image Bot (@AnimeQuoteImage) July 4, 2019
~ Robert Kennedy pic.twitter.com/BiKV7K3Ls2
"Heaven has no rage like love to hatred turned, nor hell a fury like a woman scorned."— Anime Quote Image Bot (@AnimeQuoteImage) July 5, 2019
~ William Congreve pic.twitter.com/0PKZUlsMaH
One in particular looked like a bizarre, if late, tribute to pride month.
"There is only one kind of love, but there are a thousand imitations."— Anime Quote Image Bot (@AnimeQuoteImage) July 3, 2019
~ Francois de La Rochefoucauld pic.twitter.com/Z76LMv41ao
Some thought-provoking quotes actually seemed enhanced by their images.
"The psychical, whatever its nature may be, is itself unconscious."— Anime Quote Image Bot (@AnimeQuoteImage) July 5, 2019
~ Sigmund Freud pic.twitter.com/cpHLdHIwQd
"I am sorry to think that you do not get a man's most effective criticism until you provoke him. Severe truth is expressed with some bitterness."— Anime Quote Image Bot (@AnimeQuoteImage) July 5, 2019
~ Henry David Thoreau pic.twitter.com/XKgYr1YXpv
Others didn't make me think as much as send a chill down my spine.
"There is nothing which at once affects a man so much and so little as his own death."— Anime Quote Image Bot (@AnimeQuoteImage) July 3, 2019
~ Samuel Butler pic.twitter.com/Iv68wFqGXz
"What we have to do, what at any rate it is our duty to do, is to revive the old art of Lying."— Anime Quote Image Bot (@AnimeQuoteImage) July 5, 2019
~ Oscar Wilde pic.twitter.com/yko10ZnwvG
This one in particular still freaks me out. A quote about "positive vision" paired with an inverted image of someone with blood on their shirt and a hidden face. I really hope this was random and not a secret prophecy for the coming End of Days.
"In order to carry a positive action we must develop here a positive vision."— Anime Quote Image Bot (@AnimeQuoteImage) July 4, 2019
~ Dalai Lama pic.twitter.com/iLm7Ws60Ci
There's also many political quotes that get mixed in. Pairing real-world politics with anime is frequently...awkward.
"In this world of sin and sorrow there is always something to be thankful for as for me, I rejoice that I am not a Republican."— Anime Quote Image Bot (@AnimeQuoteImage) July 3, 2019
~ H. L. Mencken pic.twitter.com/H4NF6iCGww
"Richard Nixon is a no good, lying b-----d. He can lie out of both sides of his mouth at the same time, and if he ever caught himself telling the truth, he'd lie just to keep his hand in."— Anime Quote Image Bot (@AnimeQuoteImage) July 5, 2019
~ Harry S. Truman pic.twitter.com/gcWNotlccj
There of course will be some creations I simply don't know how to respond to.
"Nature hates calculators."— Anime Quote Image Bot (@AnimeQuoteImage) July 4, 2019
~ Ralph Waldo Emerson pic.twitter.com/X23BkHHyjX
"The simple truth is that balding African-American men look cool when they shave their heads, whereas balding white men look like giant thumbs."— Anime Quote Image Bot (@AnimeQuoteImage) July 5, 2019
~ Dave Barry pic.twitter.com/sTg5MdZMqn
"True friends stab you in the front."— Anime Quote Image Bot (@AnimeQuoteImage) July 4, 2019
~ Oscar Wilde pic.twitter.com/XXaQEzSsxC
Lastly, here's my all-time favorite that's truly one of a kind, and other programmers who have handled APIs will likely appreciate it.
""— Anime Quote Image Bot (@AnimeQuoteImage) July 4, 2019
Either the API crapped out on me, or this is one of those "imagine your own quote" scenarios. If so, I'd go with a computer science quote about unit testing.
Wrapping Up #
Making a bot like this has been a far-off goal of mine for a long time, and making it real has reminded me of why I enjoy programming so much. Many things that seem impossible to make usually aren't if you keep at it and try enough different approaches. I looked at several Ruby setups for this before finally settling on Node, and after a few days of struggling to get things working on Heroku, it all finally came together.
Now I can kick back and enjoy it doing this work for me. At least until the cycle repeats and I get another idea that both improves my programming skills, indulges my love of anime, and costs me some sleep in the process.
"The privilege of a lifetime is being who you are."— Anime Quote Image Bot (@AnimeQuoteImage) July 7, 2019
~ Joseph Campbell pic.twitter.com/O1TtaPc82M