petercarrjones / Markov-Tweet

A Markov text generator that pushes text to Twitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"BillBlakeBot"

============

This python library is available for use under a Creative Commons license. Please give attribution to myself and Megan Speir if you choose to use or fork this script.

@autoblake is a Twitter bot that tweets Markov-chain generated lines from David Erdman's The Complete Poetry and Prose of William Blake.

About

@autoblake is a fork of Megan Speir's "Markov_Tweet.py" that grabs words from Blake's corpus, then forms a chain of text based upon the probability that one particular word follows another.

Installation

To create your own text-based Markov Twitter bot, do the following:

  1. Download the python libraries that "BillBlakeBot" needs to function. Make sure you get the most recent versions.
    • virtualenv: Allows you to sidestep security issues that pop up whenever python scripts require write access to your server. "virtualenv" also includes several libraries like "pip" and "easy_install" that make installing new libraries much easier.
    • simplejson:Allows you to access the Twitter API, in order to generate tweets.
    • oauth2: Sends requests to the Twitter API, in the form of consumer keys and access tokens.
    • httplib2: HTTP Client Library that gives the program the ability to execute HTTP requests.
    • python twitter: Allows you to interface with the Twitter API.
  2. Find a server to host your bot, and ssh connect to that server using the command line. Here is a good overview of using ssh to connect to a remote server with the command line.
  3. Make the following changes to the code in the package:
    • In "markov_class.py
      • Change twitter_handle on line 53 with your intended handle.
      • If you are unhappy with the number of words in the sentence, the amount of randomness, or the patterns, you may want to change the value on line 36 to suit your particular needs. The base is "2", but different corpuses work differently.
    • In "markov_tweet.py
      • Change handle = "autoblake" with your intended handle.
      • Create an application on http://dev.twitter.com, change the settings for "OAuth" and "Your Access Token" to "read and write" (default is read-only), generate an access token, and take note of the consumer key, consumer secret, access token, and access token secret.
      • Put the specified values in the appropriate spaces in lines 33-6 (ex, tokens and secrets are often written in this manner "5g&i983T$fq").
      • If you wish to use a corpus besides blake.txt, save intended corpus in a txt file (NOT a .doc file), place in "BillBlakeBot" folder, and replace f=open(blake.txt) on line 25 with the filename of your corpus.
      • If you are unhappy with the result of the Markov chain you generate, change order = int(2) on line 10 with a different Markov order. Higher order numbers tend to generate more repetition, while lower order numbers tend to generate more randomness.
  4. Upload the "Markov-Tweet" folder to your server.
  5. Initiate the script by ssh-ing back into your server and, in the correct folder, typing python markov_tweet.py.
  6. If the script works, set it to initiate every few hours (3-6 at the least) by setting it to Cron, either with your web service (most hosts have an interface for cronjobs) or by following the instructions here.

About

A Markov text generator that pushes text to Twitter