Brandon Roots
  • INTERACTIVE
  • FILM
  • ABOUT
  • CONTACT
October 17, 2020

I Had A Dream Bot

broots ITP, Programming A to Z

Tweets by HadzDream

Coming up with an idea for a bot is easy! Choosing one to make is hard. I pitched a dozen concepts to friends and family before setting on one that felt right. After much hemming and hawing hearing my husband mention his co-worker Adream triggered it. A dream! That was it! I have always had an interest in dreams and certainly Twitter would be full of tweets mentioning the relatable and bizarre dreams that everyone has.

So what does the bot do? It essentially acts as a dream aggregator. I’ll break it down into two parts: the code and running on a Raspberry Pi.

The Code: The basic behavior for the bot is once an hour to search for ten tweets that contain the words “I had a dream”. From there it filters through the tweets, removing any text before “I had a dream”, discarding any tweets with profanity, removing any @’s, discarding any tweets 110 characters or longer, and from whatever is left posting the first to meet all of the criteria.

Running in node.js I made use of two node packages, Twit and Bad-words. Twit made searching for tweets easy using the following code:

//  search twitter for all tweets containing the phrase "I had a dream"
  T.get('search/tweets', { q: '"I had a dream"', count: 10, since_id: id}, function(err, data, response) {
    // do something with data
}

From there I iterated through the returned JSON object with a for loop. My initial tests returned quite a few hits with profanity which is where the Bad-words package comes in. Using Bad-words I discarded any tweets containing profane language:

// filter out profane tweets
  if(!filter.isProfane(tweetText)) {
    // do something with tweets that pass filter
}

With the code working the next question was where to run it?

Raspberry Pi: Fortunately a few years back I purchased a Raspberry Pi 3b that was still sitting in a drawer waiting for a purpose. Getting it up and running was pretty straightforward following the documentation from the Raspberry Pi organization. Mine was running an OS two versions old so I downloaded a fresh install using the Raspberry Pi Imager to update the OS. From there I was able to tunnel in with SSH via command line and screen share with VNC. Installing node and other packages used the same process as terminal in OS X.

Where I did run into a challenge was figuring out how to transfer files to the Pi. By default the Pi didn’t appear as an SMB server on my Mac so a little digging lead me to this resource for setting up a Samba Server on a Pi.

This whole process went surprisingly well and now I have my own little Twitter bot humming away doing a new post every hour.

You can follow I Had A Dream on Twitter at @HadzDream.

Project 1: Dodeca – Part 2 Lab: Intro to Asynchronous Serial Communications

Related Posts

Fractal Plant – Foiled by  Registers

Homemade Hardware, ITP, Solar Plant

Fractal Plant – Foiled by Registers

Since receiving the PCBs and successfully soldering the board together I have been trying to rewrite code for the I2C port expander. This has been immensely difficult! The Inkplate Arduino Library makes considerable use of an “Mcp” class, which is written to work with the MCP23017 GPIO expander IC. These chips are quite difficult to […]

“Handling” Playtest Week

Handling, ITP

“Handling” Playtest Week

Last week we attended “Playtest Thursday” on the second floor of 370 Jay St with our games. I came away from the experience with some very specific feedback. Seeing a number of people play the game showed me things I didn’t anticipate. Some folks approached the cabinet and immediately treated it as a touch screen. […]

Fractal Plant – Beta Build

Homemade Hardware, ITP, Solar Plant

Fractal Plant – Beta Build

The boards arrived! Amazingly within an hour of one another. Based on the experience I think that JLCPCB is a better value. With shipping OSHPark was $55.50 for 3 boards. JLCPCB was $26.36 for 10 boards. Aside from a higher cost OSHPark also left sharp bits of tabs around the edges of the boards which […]

Recent Posts

  • Fractal Plant – Foiled by  RegistersFractal Plant – Foiled by Registers
    May 9, 2022
  • “Handling” Playtest Week“Handling” Playtest Week
    May 5, 2022
  • Fractal Plant – Beta BuildFractal Plant – Beta Build
    April 24, 2022
Brandon Roots