tweetomator 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/composers/composer.rb +1 -0
- data/lib/composers/markov_composer.rb +11 -6
- data/lib/composers/random_composer.rb +1 -1
- data/lib/config/config.rb +3 -2
- data/lib/tweet.rb +8 -8
- data/lib/tweetomator/version.rb +1 -1
- data/test/lib/composers/markov_composer_test.rb +2 -2
- data/test/lib/composers/random_composer_test.rb +4 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c236c8c5a61cb44e41f72ea90ff1456d9410a12
|
4
|
+
data.tar.gz: def353fd186f96425936d53df3a4ad20cbfaf257
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b79c91124edaa43786d5ebf22e34b84a533fb254ae4409afa49c96ee7f9286c70abf0cfc4ee6fde7fe7fa7bed66cc7597c95373286d74fe4e09426b0a26e346c
|
7
|
+
data.tar.gz: 14d1b4c40016cc50c67f2e5b00ad4a89b9cf3687358eab21131791b57725782385fd6f91ad9948edb9d4b4d1fc5029d18b8ba57a9cbf31bf87c48abed2e73f3f
|
data/lib/composers/composer.rb
CHANGED
@@ -3,6 +3,7 @@ class Composer
|
|
3
3
|
@max_length = config.twitter_config.tweet_max_length
|
4
4
|
@blacklist = config.blacklist
|
5
5
|
@stop_words = config.stop_words
|
6
|
+
@default_hashtag = config.default_hashtag
|
6
7
|
@twitter_client = twitter_client
|
7
8
|
@tweet_finder = tweet_finder
|
8
9
|
@emoji_finder = emoji_finder
|
@@ -56,20 +56,21 @@ class MarkovComposer < Composer
|
|
56
56
|
|
57
57
|
def clean_up(text)
|
58
58
|
text = text.strip.capitalize
|
59
|
-
if text[text.length-1].match('[A-Za-z]') != nil && text.length < @max_length
|
59
|
+
if text[text.length - 1].match('[A-Za-z]') != nil && text.length < @max_length
|
60
60
|
text << %w(. ! ? . .).sample
|
61
61
|
end
|
62
62
|
text
|
63
63
|
end
|
64
64
|
|
65
65
|
def create_tweet(text)
|
66
|
-
|
66
|
+
hashtags = []
|
67
|
+
hashtags << @default_hashtag if @default_hashtag != '' && (text.length + @default_hashtag.length + 2) < @max_length
|
68
|
+
tweet = Tweet.new(text, hashtags, @twitter_client)
|
69
|
+
if [true, false].sample
|
67
70
|
hashtag = @lines.sample.split.reject { |w| w.strip.nil? || /[^A-Za-z]/.match(w.strip) != nil || @stop_words.include?(w.strip) }.sample
|
68
|
-
if hashtag != nil && (
|
69
|
-
return Tweet.new(text, hashtag.downcase, @twitter_client)
|
70
|
-
end
|
71
|
+
tweet.hashtags << hashtag if hashtag != nil && (tweet.length + hashtag.length + 2) < @max_length
|
71
72
|
end
|
72
|
-
|
73
|
+
tweet
|
73
74
|
end
|
74
75
|
|
75
76
|
def insert_emoji(tweet)
|
@@ -77,4 +78,8 @@ class MarkovComposer < Composer
|
|
77
78
|
tweet.append(@emoji_finder.find)
|
78
79
|
end
|
79
80
|
end
|
81
|
+
|
82
|
+
def hashtag_fits?(tweet, hashtag)
|
83
|
+
hashtag != nil && (tweet.length + hashtag.length + 1) < @max_length
|
84
|
+
end
|
80
85
|
end
|
@@ -17,7 +17,7 @@ class RandomComposer < Composer
|
|
17
17
|
text = trim(text, hashtag.length)
|
18
18
|
text = replace_a_word(text.split.sample, text)
|
19
19
|
text = replace_a_word(emoji, text)
|
20
|
-
Tweet.new(text.capitalize, hashtag, @twitter_client)
|
20
|
+
Tweet.new(text.capitalize, [hashtag], @twitter_client)
|
21
21
|
end
|
22
22
|
|
23
23
|
def compose_image_query(query)
|
data/lib/config/config.rb
CHANGED
@@ -37,9 +37,9 @@ end
|
|
37
37
|
class TweetomatorConfig
|
38
38
|
include Validatable
|
39
39
|
|
40
|
-
attr_reader :twitter_config, :flickr_config, :topics, :blacklist, :stop_words, :delay_in_seconds, :composer_type, :input_text_file
|
40
|
+
attr_reader :twitter_config, :flickr_config, :topics, :blacklist, :stop_words, :delay_in_seconds, :composer_type, :input_text_file, :default_hashtag
|
41
41
|
|
42
|
-
def initialize(twitter_config, flickr_config, topics, blacklist, stop_words, delay_in_seconds, composer_type, input_text_file)
|
42
|
+
def initialize(twitter_config, flickr_config, topics, blacklist, stop_words, delay_in_seconds, composer_type, input_text_file, default_hashtag='')
|
43
43
|
@twitter_config = twitter_config
|
44
44
|
@flickr_config = flickr_config
|
45
45
|
@topics = topics
|
@@ -48,5 +48,6 @@ class TweetomatorConfig
|
|
48
48
|
@delay_in_seconds = delay_in_seconds
|
49
49
|
@composer_type = composer_type
|
50
50
|
@input_text_file = input_text_file
|
51
|
+
@default_hashtag = default_hashtag
|
51
52
|
end
|
52
53
|
end
|
data/lib/tweet.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
class Tweet
|
2
|
-
|
2
|
+
attr_accessor :hashtags
|
3
3
|
|
4
|
-
def initialize(text,
|
4
|
+
def initialize(text, hashtags, twitter_client)
|
5
5
|
@text = text
|
6
|
-
@
|
6
|
+
@hashtags = hashtags
|
7
7
|
@twitter_client = twitter_client
|
8
8
|
end
|
9
9
|
|
10
10
|
def post!(image = '')
|
11
11
|
if image.length > 0 && File.exists?(image)
|
12
|
-
@twitter_client.update_with_media(self.
|
12
|
+
@twitter_client.update_with_media(self.with_hashtags, File.new(image))
|
13
13
|
File.delete(image)
|
14
14
|
else
|
15
|
-
@twitter_client.update(self.
|
15
|
+
@twitter_client.update(self.with_hashtags)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
(@
|
19
|
+
def with_hashtags
|
20
|
+
(@hashtags && @hashtags.size > 0) ? "#{@text}#{hashtags.reduce('') { |str, h| str << " ##{h}" }}" : @text
|
21
21
|
end
|
22
22
|
|
23
23
|
def length
|
24
|
-
|
24
|
+
with_hashtags.length
|
25
25
|
end
|
26
26
|
|
27
27
|
def append(text)
|
data/lib/tweetomator/version.rb
CHANGED
@@ -19,6 +19,7 @@ class TestMarkovComposer < Minitest::Unit::TestCase
|
|
19
19
|
mock_config = Minitest::Mock.new
|
20
20
|
mock_config.expect :twitter_config, mock_twitter_config
|
21
21
|
mock_config.expect :blacklist, @blacklist
|
22
|
+
mock_config.expect :default_hashtag, 'potato'
|
22
23
|
mock_config.expect :stop_words, @stop_words
|
23
24
|
mock_config.expect :input_text_file, 'text.txt'
|
24
25
|
mock_text_reader = MiniTest::Mock.new
|
@@ -32,7 +33,6 @@ class TestMarkovComposer < Minitest::Unit::TestCase
|
|
32
33
|
|
33
34
|
def test_that_tweet_is_short_enough
|
34
35
|
tweet = @markov_composer.compose_tweet
|
35
|
-
|
36
|
-
assert tweet.with_hashtag.length <= @max_length, true
|
36
|
+
assert tweet.with_hashtags.length <= @max_length, true
|
37
37
|
end
|
38
38
|
end
|
@@ -23,22 +23,23 @@ class TestRandomComposer < Minitest::Unit::TestCase
|
|
23
23
|
mock_config.expect :twitter_config, mock_twitter_config
|
24
24
|
mock_config.expect :max_length, @max_length
|
25
25
|
mock_config.expect :blacklist, @blacklist
|
26
|
+
mock_config.expect :default_hashtag, 'potato'
|
26
27
|
mock_config.expect :stop_words, @stop_words
|
27
28
|
@random_composer = RandomComposer.new(mock_config, mock_tweet_client, mock_tweet_finder, mock_emoji_finder)
|
28
29
|
end
|
29
30
|
|
30
31
|
def test_that_tweet_is_short_enough
|
31
32
|
tweet = @random_composer.compose_tweet
|
32
|
-
assert tweet.
|
33
|
+
assert tweet.with_hashtags.length <= @max_length, true
|
33
34
|
end
|
34
35
|
|
35
36
|
def test_that_blacklisted_words_are_removed
|
36
37
|
tweet = @random_composer.compose_tweet
|
37
|
-
refute tweet.
|
38
|
+
refute tweet.with_hashtags.split.any? { |word| @blacklist.include?(word) }, true
|
38
39
|
end
|
39
40
|
|
40
41
|
def test_that_links_are_removed
|
41
42
|
tweet = @random_composer.compose_tweet
|
42
|
-
refute tweet.
|
43
|
+
refute tweet.with_hashtags.split.any? { |word| %w(kck.st/1pLytCe http://nyan.cat).include?(word) }, true
|
43
44
|
end
|
44
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tweetomator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nat Young
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07
|
11
|
+
date: 2015-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|