Skip to content

Instantly share code, notes, and snippets.

@mcoms
Created June 6, 2017 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcoms/056c080c8771d221e1be1ddc743f95bd to your computer and use it in GitHub Desktop.
Save mcoms/056c080c8771d221e1be1ddc743f95bd to your computer and use it in GitHub Desktop.
Train a Markov chain on your tweets so you don't have to think of tweets anymore
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'marky_markov', '~> 0.3.5'
gem 'twitter', '~> 6.1.0'
require 'bundler'
Bundler.require
client = Twitter::REST::Client.new do |config|
config.consumer_key = '...'
config.consumer_secret = '...'
config.access_token = '...'
config.access_token_secret = '...'
end
tweets = client.user_timeline(client.user.id, count: 200, trim_user: true, exclude_replies: true, contributor_details: false, include_rts: false)
markov = MarkyMarkov::Dictionary.new('twitter_dictionary')
tweets.each {|t| markov.parse_string t.full_text }
markov.save_dictionary!
puts markov.generate_n_words 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment