Slides, examples and code for "build-a-bot workshop" at Social Media Week NYC 2016.
http://socialmediaweek.org/newyork/events/twitter-bots/
- 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
@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
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
- Setting Up a Twitter Bot in 5 Easy Steps
- Get you project directory organized
- Register a Twitter app
- Create a Twitter account
- OAuth secret handshake
- Store your secrets somewhere safe
- 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
git clone https://github.com/nmacri/twitter-bots-smw-2016.git
- 😕 "huh, git what?" --- don't sweat it, you can download as a zip file instead.
- cd to your project folder. in my case it's
cd ~/twitter-bots-smw-2016
- If you haven't already, install virtualenv so you can run this in a clean python environment.
- 😕 "err, python's not really my thing?" ---- it's cool. There's a javascript example here, but it's kind of janky.
- Here are a few things that are way more awesome and useful:
- Libraries that support the Twitter API
- RiTa: A toolkit for computational literature implemented in Java and Javascript with integrations for Processing, Android, Note, P5.js, Broswerify, Bower, etc.
- Create an isolated virtual environment for this project to run in:
virtualenv venv
. - Activate your virtualenv using
source venv/bin/activate
- Once you've activated your virtualenv, you'll need to install some dependencies:
pip install -r requirements.txt
- Start by working through the jupyter notebooks in '/notebooks':
cd notebooks && jupyter notebook
(or if you prefer you can view them online)
- Social Media Week Talk Descriptions
- Social Media Week Tweet Archive
- Kanye West Quotes
- Kanye West Tweets
- 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
- 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
- Build a basic local datastore that can support the storage needs of other classes. It will need:
- A
tweets
table
- production account
- staging account
- 3-4 test interlocutors
- A fake dataset for testing schedule-driven tweets
- 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.
- git deployment on production server
- Reaveal templates and build framework
- Node app working locally
- Node app working on gh-pages
- Training selectors on web app
- Docstrings on framework library
- Readme description of framework library