-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_ebooks.rb
68 lines (56 loc) · 2.08 KB
/
text_ebooks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/ruby
#based on https://gist.github.com/busterbenson/6695350, modified by @peteyreplies
# Make sure you have these gems installed
require 'rubygems'
require 'thread'
require 'twitter'
require 'marky_markov'
require 'date'
# Create a new Twitter account that you'd like to have your auto-tweets posted to
# Go to dev.twitter.com, 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.
CONSUMER_KEY = 'YOUR_KEY'
CONSUMER_SECRET = 'YOUR_SECRET'
ACCESS_TOKEN = 'YOUR_ACCESS_TOKEN'
ACCESS_TOKEN_SECRET = 'YOUR_ACCESS_TOKEN_SECRET'
PATH_TO_TEXT = 'YOUR_TEXT.csv'
ARCHIVED_TWEETS = 'ARCHIVED_TWEETS.csv'
### -----------------------------------------------------------------------------------------------------
#auth to twitter
client = Twitter::REST::Client.new do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.access_token = ACCESS_TOKEN
config.access_token_secret = ACCESS_TOKEN_SECRET
end
#randomly select lucidity on each run; 1 less lucid, 3 more
n = rand(1..3)
markov = MarkyMarkov::TemporaryDictionary.new(n)
markov.parse_file PATH_TO_TEXT
#randomly select whether it generates 1 or 2 sentences, and generate them until you come in under 140
under140 = false
begin
m = rand(1..2)
tweet_text = markov.generate_n_sentences(m).split(/\#\</).first.chomp.chop
if tweet_text.length <= 140 then
under140 = true
end
end until under140 == true
#D20 that the tweet will be all caps because LOUD NOISES
d = rand(1..20)
if d == 20
tweet_text = tweet_text.upcase
end
#markov.save_dictionary!
markov.clear! # Clear the temporary dictionary because otherwise it's huge.
#printing tweet locally
puts tweet_text
#append to archival csv w/ date and time
date = Time.now.strftime("%m/%d/%Y")
time = Time.now.strftime('%H:%M"')
CSV.open(ARCHIVED_TWEETS, "a") do |csv|
csv << [date, time, tweet_text]
# ...
end
#post to twitter (comment out to debug locally)
client.update(tweet_text)