Software Development
Robotics / Social media / Web development

Code Annotated: How this Groupon dev built a news-poetry Twitter bot

Jonathan Julian shares a few lines of code from a fun side project he's working on.

What Jonathan Julian is working on. (Screenshot)

This is a new series called Code Annotated, in which we ask local technologists what they’re developing. This is a guest post from Baltimore-based iOS developer Jonathan Julian.

I like the simplicity and playfulness of Twitter bots. Take some serious input, make some changes, and spit it out in a tweet.
Playing around with news headlines can be especially fun. Inspired by the wacky headlines of today as well as bots like @twoheadlines and @CNNyourmom, I started playing around with my own news-headlines-as-poetry Twitter bot (coming soon). This is the meaty center of it:

news = get_news()
titles = news[‘articles’].shuffle.take(3).map { |article| article[‘title’] }
phrases = { |title| title.gsub(/[^\w\s]/, ”).split(‘ ‘).shuffle.take(2).join(‘ ‘) }
tweet phrases.shuffle.join(‘ ‘)

The news object contains articles which each have a title. To make a six-word poem from three article titles, we have to randomly choose three articles, strip out all punctuation (gsub) and randomly choose two words. Then combine the three pairs of words to form the poem. Here are some examples:

  • Not All of Associates Ears Anchors
  • Cost Yiannopouloss Clintons in Russia Trump
  • Security McMaster Remark Nation of BackChannel

This code is written in Ruby, which is an easy-to-read programming language that is great at text processing. I lean on Ruby for my other Twitter bots too: @bmorejuryduty, @manningdotd and @artmeme14. I’m still thinking about what I can do with these “news poems,” what do you think?
As you can see, there’s not much to making a simple bot, so maybe you should give it a try.

Companies: Groupon

Join the conversation!

Find news, events, jobs and people who share your interests on's open community Slack


Baltimore daily roundup: Mayoral candidates talk tech and biz; a guide to greentech vocabulary; a Dutch delegation's visit

Baltimore daily roundup: Medtech made in Baltimore; Sen. Sanders visits Morgan State; Humane Ai review debate

Baltimore daily roundup: An HBCU innovation champion's journey; Sen. Sanders visits Morgan State; Humane Ai review debate

'Fail fast and fail forward': This accelerator and HBCU summit founder believes in seizing the moment

Technically Media