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 Technical.ly 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 = titles.map { |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
Engagement

Join the conversation!

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

Trending

Baltimore daily roundup: HR's big AI-influenced shift; EDA Tech Hubs lessons; DCHD's $2.25M in grants

Baltimore daily roundup: Bowie State's esports reputation; AI impersonator arrested; EpiWatch names new CEO

Baltimore daily roundup: Real estate deal in the Peninsula; Missing $100M nitrile glove factory; Dirt bike clampdown

Edtech CEO looks back on the promises of summer 2020: 'It never rang true to me'

Technically Media