Skip to content

Instantly share code, notes, and snippets.

Created September 25, 2013 05:05
Show Gist options
  • Save busterbenson/6695350 to your computer and use it in GitHub Desktop.
Save busterbenson/6695350 to your computer and use it in GitHub Desktop.
How I do @buster_ebooks.
# Make sure you have these gems installed
require 'rubygems'
require 'thread'
require 'csv'
require 'twitter'
require 'marky_markov'
# Create a new Twitter account that you'd like to have your auto-tweets posted to
# Go to, create a new application with Read+Write permissions
# Create an access token + secret for the account and copy that and the consumer key and secrets here.
PATH_TO_TWEETS_CSV = 'tweets.csv'
PATH_TO_TWEETS_CLEAN = 'markov_dict.txt'
### -----------------------------------------------------------------------------------------------------
# Go to -> Settings -> Download Archive.
# This tweets.csv file is in the top directory. Put it in the same directory as this script.
csv_text = CSV.parse(
# Create a new clean file of text that acts as the seed for your Markov chains, 'w') do |file|
csv_text.reverse.each do |row|
# Strip links and new lines
tweet_text = row[5].gsub(/(?:f|ht)tps?:\/[^\s]+/, '').gsub(/\n/,' ')
# Save the text
# Run when you want to generate a new Markov tweet
markov ='dictionary') # Saves/opens dictionary.mmd
markov.parse_file PATH_TO_TWEETS_CLEAN
tweet_text = markov.generate_n_sentences(2).split(/\#\</).first.chomp.chop
# Connect to your Twitter account
Twitter.configure do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
twitter_client = => ACCESS_TOKEN,
:oauth_token_secret => ACCESS_TOKEN_SECRET)
p "#{}: #{tweet_text}"
Copy link

parkr commented Sep 29, 2013

If you'd like a gem version, check out

Copy link

buster, parkr - what does dictionary.mmd do? After three iterations, mine is 66 megabytes (I have a large corpus), and I'm trying to figure out what to do to keep it manageable.

e: looks like there is an option in markymarkov to replace permanent dictionary w/ a temp one:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment