twords 0.2.2 → 0.2.3
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/README.md +4 -0
- data/lib/twords.rb +1 -0
- data/lib/twords/configuration.rb +7 -5
- data/lib/twords/follower_bot_cop.rb +67 -0
- data/lib/twords/instance_methods.rb +1 -0
- data/lib/twords/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c34c3b4415dc5107328e127712381efc0a84562
|
4
|
+
data.tar.gz: d90029ae4175a52dd886ac459d7023ac5aa1cd9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7eada355aa2b6c1aaf30fcff26ca51bab3626ef05ed6dea0d40ca5431426787308cc04050290564f0efc29b31b740eb348edd212e04c71d0f2f5201b83b3480
|
7
|
+
data.tar.gz: 6b42cffee275451b7cf64d73003ca4d418b7bb9ba4a970de833407450c6f9076bceefb1d264990420054e3fd9cffd44737872e002e6ee256247dfb66fa4aedde
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|

|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/twords)
|
4
|
+
[](https://codeclimate.com/github/msimonborg/twords)
|
5
|
+
[](http://inch-ci.org/github/msimonborg/twords)
|
6
|
+
|
3
7
|
## Twitter word clouds
|
4
8
|
|
5
9
|
Count the occurrences of words in a tweeter's tweets.
|
data/lib/twords.rb
CHANGED
data/lib/twords/configuration.rb
CHANGED
@@ -121,7 +121,8 @@ class Twords
|
|
121
121
|
end
|
122
122
|
alias include_urls= include_uris=
|
123
123
|
|
124
|
-
# Set whether @-mentions should be counted.
|
124
|
+
# Set whether @-mentions should be counted.
|
125
|
+
# If true, any word beginning with "@" will be ignored.
|
125
126
|
#
|
126
127
|
# @param boolean [true, false] will raise an error if the value is not a Boolean value
|
127
128
|
def include_mentions=(boolean)
|
@@ -129,16 +130,17 @@ class Twords
|
|
129
130
|
@include_mentions = boolean
|
130
131
|
end
|
131
132
|
|
132
|
-
# Takes a block and stores for lazy evaluation to define the end of the
|
133
|
-
# The return value of the block must respond
|
133
|
+
# Takes a block and stores for lazy evaluation to define the end of the
|
134
|
+
# time range being checked. The return value of the block must respond
|
135
|
+
# to #to_time and return a Time object when called.
|
134
136
|
#
|
135
137
|
# @return [Proc]
|
136
138
|
def up_to(&time_block)
|
137
139
|
@up_to_block = time_block
|
138
140
|
end
|
139
141
|
|
140
|
-
# Calls the Proc value of #up_to_block and calls #to_time on the return value.
|
141
|
-
# to be returned.
|
142
|
+
# Calls the Proc value of #up_to_block and calls #to_time on the return value.
|
143
|
+
# Expects a Time object to be returned.
|
142
144
|
#
|
143
145
|
# @return [Time]
|
144
146
|
def up_to_time
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'pry'
|
3
|
+
require 'twords/config_accessible'
|
4
|
+
|
5
|
+
class Twords
|
6
|
+
class FollowerBotCop
|
7
|
+
include ConfigAccessible
|
8
|
+
|
9
|
+
attr_reader :screen_name, :followers, :follower_bots
|
10
|
+
|
11
|
+
def initialize(screen_name)
|
12
|
+
@screen_name = screen_name
|
13
|
+
@followers = []
|
14
|
+
@follower_bots = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def client
|
18
|
+
config.client.client
|
19
|
+
end
|
20
|
+
|
21
|
+
def detect_bots(cursor: nil)
|
22
|
+
response = client.followers(screen_name, count: 200, cursor: cursor)
|
23
|
+
count_followers_and_bots(response)
|
24
|
+
next_cursor = response.attrs[:next_cursor]
|
25
|
+
return if next_cursor == 0
|
26
|
+
detect_bots(cursor: next_cursor)
|
27
|
+
rescue Twitter::Error::TooManyRequests => error
|
28
|
+
wait_out_rate_limit_error(error)
|
29
|
+
retry
|
30
|
+
end
|
31
|
+
|
32
|
+
def count_followers_and_bots(response)
|
33
|
+
response.attrs[:users].each do |user|
|
34
|
+
@followers << user
|
35
|
+
@follower_bots << user if a_bot?(user)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def wait_out_rate_limit_error(error)
|
40
|
+
reset_time = error.rate_limit.reset_in + 1
|
41
|
+
puts "Out of #{followers.count} followers, #{follower_bots.count} bots detected."
|
42
|
+
puts "That's a rate of #{percentage} out of 100."
|
43
|
+
puts "Hit rate limit, waiting #{reset_time} seconds. "
|
44
|
+
sleep reset_time
|
45
|
+
end
|
46
|
+
|
47
|
+
def a_bot?(user)
|
48
|
+
if user[:statuses_count] <= 10
|
49
|
+
user[:default_profile_image] == true ||
|
50
|
+
user[:followers_count].zero? ||
|
51
|
+
bot_like_timeline?(user)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def bot_like_timeline?(user)
|
56
|
+
return true if user[:statuses_count].zero?
|
57
|
+
return false if user[:protected] == true
|
58
|
+
timeline = client.user_timeline(user[:screen_name])
|
59
|
+
timeline.all? { |tweet| tweet.reply? || tweet.retweet? }
|
60
|
+
end
|
61
|
+
|
62
|
+
def percentage
|
63
|
+
return 0.0 if followers.count.zero?
|
64
|
+
(follower_bots.count / followers.count.to_f * 100).round(2)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/twords/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twords
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- M. Simon Borg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/twords.rb
|
70
70
|
- lib/twords/config_accessible.rb
|
71
71
|
- lib/twords/configuration.rb
|
72
|
+
- lib/twords/follower_bot_cop.rb
|
72
73
|
- lib/twords/instance_methods.rb
|
73
74
|
- lib/twords/twitter_client.rb
|
74
75
|
- lib/twords/version.rb
|