-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitterbot.rb
More file actions
executable file
·93 lines (79 loc) · 2.07 KB
/
Copy pathtwitterbot.rb
File metadata and controls
executable file
·93 lines (79 loc) · 2.07 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require 'twitter'
require 'marky_markov'
markov = MarkyMarkov::TemporaryDictionary.new
# All of the imformation below comes from twitter's
# API. You'll obviously need to enable write
client = Twitter::REST::Client.new do |config|
config.consumer_key = "YOU CONSUMER KEY"
config.consumer_secret = "YOUR CONSUMER SECRET"
config.access_token = "YOUR ACCESS TOKEN"
config.access_token_secret = "YOUR ACCESS TOKEN SECRET"
end
pwd = Dir.pwd
def syllableCount(word)
word.downcase!
return 1 if word.length <= 3
word.sub!(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, '')
word.sub!(/^y/, '')
return word.scan(/[aeiouy]{1,2}/).size
end
def haikuGen(tweetout)
haiku = ""
total = 0
check = 0
tweetout.split(" ").each do |word|
haiku << "#{word} "
total += syllableCount(word)
if total == 7
haiku << "\n"
check += 1
end
if total == 12
check += 1;
haiku << "\n"
end
if total == 19 && check == 2
haiku << "\n"
return haiku
end
end
return 0
end
def collect_with_max_id(collection=[], max_id=nil, &block)
response = yield(max_id)
collection += response
response.empty? ? collection.flatten : collect_with_max_id(collection, response.last.id - 1, &block)
end
def client.get_all_tweets(user)
collect_with_max_id do |max_id|
options = {count: 200, include_rts: false}
options[:max_id] = max_id unless max_id.nil?
user_timeline(user, options)
end
end
user = "USERNAME TO BUILD DICTIONARY"
client.get_all_tweets(user).each do |tweet|
# Removing any mentions of other people or links
markov.parse_string tweet.text.gsub /(http.*?( |$))|(@.*?( |$))/, ''
end
if(ARGV[0] != '-h')
tweetout = markov.generate_1_sentences
while tweetout.length > 140
tweetout = markov.generate_1_sentences
end
end
if(ARGV[0] == '-h')
tweetout = haikuGen(markov.generate_1_sentences)
while tweetout == 0 || tweetout.length > 140
tweetout = haikuGen(markov.generate_1_sentences)
end
end
puts("#{tweetout} \n'y' to post this, anything else to not")
answer = STDIN.gets.chomp
if answer != "y"
exit
end
client.update("#{tweetout}")
puts "Posted!"
markov.clear!
exit