Creative Commons license. Please give attribution to myself and Megan Speir if you choose to use or fork this script.This python library is available for use under a
@autoblake is a Twitter bot that tweets Markov-chain generated lines from David Erdman's The Complete Poetry and Prose of William Blake.
@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.
To create your own text-based Markov Twitter bot, do the following:
- 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.
- In "markov_class.py
twitter_handleon 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
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.