Skip to content

nmacri/twitter-bots-smw-2016

Repository files navigation

Let's Build a Twitter Bot Together!

Slides, examples and code for "build-a-bot workshop" at Social Media Week NYC 2016.

http://socialmediaweek.org/newyork/events/twitter-bots/

Features

  • An extensible python-based framework for standing up simple MVP twitter bots
  • Slides from Nick's Talk "Twitter Bots and The Automation of Everything" at Social Media Week NYC February 22, 2015
  • Tutorial Jupyter Notebooks walking through the process of building a bot
  • Production code for @SmwKanye A simple rules-based markov twitter bot for Social Media Week NYC 2016.
  • A small web-app example that lets you remix your own Markov Babblers

Getting Started

The Bot

@SmwKanye is built from the following compontents, all of which are contained in the /library module. Rules are spaghetti-coded together in kanye_bot.py and it runs on a once-a-minute cron job.

  • Four MarkovBabbler, trained on different text data sets
    • Recent SMW Tweets
    • All SMW Tweets
    • The SMW Theme Manifesto + Event Titles & Descriptions
    • A lot of Kanye text (tweets, interviews, lyrics, etc.)
  • Two TwitterListeners subscribed to the following queries
    • '#SMWNYC OR "social media week" OR @SMWNYC OR #SMWbot OR @SmwKanye'
    • (#smwnyc OR "social bots" OR "social media week" OR "twitter bots" OR "twitter bot" OR "social bot" OR #SMWbots OR #SMWbot)
  • One production TwitterBot and three test bots

Slides

Slides from Nick's Talk "Twitter Bots and The Automation of Everything" at Social Media Week NYC February 22, 2015

The default keyboard shortcuts are:

  • Up, Down, Left, Right: Navigation
  • f: Full-screen
  • s: Show slide notes
  • o: Toggle overview
  • . (Period or b: Turn screen black
  • Esc: Escape from full-screen, or toggle overview

Tutorial Notebooks

  1. Setting Up a Twitter Bot in 5 Easy Steps
  2. Get you project directory organized
  3. Register a Twitter app
  4. Create a Twitter account
  5. OAuth secret handshake
  6. Store your secrets somewhere safe
  7. What's a Twitter bot anyway?: An MVP Twitter bot that anyone can use
  8. What should your bot say?: Markov is just fancy name for autocomplete

Using this Repo to build your own bot

  1. git clone https://github.com/nmacri/twitter-bots-smw-2016.git
  2. cd to your project folder. in my case it's cd ~/twitter-bots-smw-2016
  3. If you haven't already, install virtualenv so you can run this in a clean python environment.
  4. Create an isolated virtual environment for this project to run in: virtualenv venv.
  5. Activate your virtualenv using source venv/bin/activate
  6. Once you've activated your virtualenv, you'll need to install some dependencies: pip install -r requirements.txt
  7. Start by working through the jupyter notebooks in '/notebooks': cd notebooks && jupyter notebook (or if you prefer you can view them online)

TODOs

Text Corpora:

  • Social Media Week Talk Descriptions
  • Social Media Week Tweet Archive
  • Kanye West Quotes
  • Kanye West Tweets

Bot Module

  • Build a basic TwitterBot class that can be used like this
bot1 = TwitterBot(**kwds)
bot2 = TwitterBot(**kwds)

text = bot1.generate_text()
reply_text = bot2.generate_text(in_reply_to=text)

tweet = bot1.tweet(text)
reply_tweet = bot2.tweet(reply_text, in_reply_to=tweet)
  • Build a bot-specific datastore for tweets that can be used like this
bot2.has_replied(tweet) #True
bot1.has_replied(reply_tweet) #False

Listener Module

  • Build a basic TwitterListener class that can be used like this
listener = TwitterListener(**kwds)

listener.backfill(50) # hits REST apis to collect relevant tweets 

listener.get_recent_tweets(6) #retreives tweets

Datastore Module

  • Build a basic local datastore that can support the storage needs of other classes. It will need:
  • A tweets table

Create Twitter Accounts

  • production account
  • staging account
  • 3-4 test interlocutors

Testing Plans

  • A fake dataset for testing schedule-driven tweets

Notebooks

  • Setting Up a Twitter Bot in 5 Easy Steps
  • What's a Twitter bot anyway?: An MVP Twitter bot that anyone can use
  • What should your bot say?: Markov is just fancy name for autocomplete
  • Kanye autocompletes your social strategy: A simple rules-based markov bot for Socal Media Week.

Server

  • git deployment on production server

Slides

  • Reaveal templates and build framework

Examples

  • Node app working locally
  • Node app working on gh-pages
  • Training selectors on web app

Documentation

  • Docstrings on framework library
  • Readme description of framework library