Skip to content

Commit a9b0d1f

Browse files
committed
Update the spaminator
1 parent 2d2a3bc commit a9b0d1f

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

app/lib/spaminator.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ def recognized_format?(text)
1010
end
1111

1212
def customer_support?(text)
13-
text.scan(/customer|support|phonenumber|phonesupport/i).size > 10
13+
text.scan(/customer|support|phonenumber|phonesupport|toll|/i).size > 10
14+
end
15+
16+
def marketing?(text)
17+
text.scan(/herb|medical|marijuana|cannabis|/i).size > 10
1418
end
1519

1620
def download_links?(text, urls, title)

lib/tasks/spam.rake

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
namespace :spam do
22
task :sweep => :environment do
3-
protips = Protip.where('created_at > ?', 7.days.ago).where(bad_content: false)
4-
good = []
3+
since = 30.days.ago
4+
5+
protips = Protip.where('created_at > ?', since).where(bad_content: false); nil
6+
good_protips = []
57
protips.each do |p|
68
flags = Spaminator.new.protip_flags(p)
79
if flags.any?
8-
puts "#{p.id} – #{p.title}#{p.body[0..100].gsub("\n", '')}"
9-
puts "#{flags.inspect}" if flags.any?
10-
puts
10+
Rails.logger.debug "#{p.id} – #{p.title}#{p.body[0..100].gsub("\n", '')}"
11+
Rails.logger.debug "#{flags.inspect}" if flags.any?
12+
Rails.logger.debug
1113

1214
p.bad_content = true
1315
p.user.bad_user = true
1416
p.save
1517
else
16-
good << p
18+
good_protips << "https://coderwall.com/p/#{p.public_id}#{p.title}"
1719
end
18-
end
20+
end; nil
1921

20-
users = User.where('created_at > ?', 7.days.ago).where(bad_user: false)
21-
users.map do |u|
22+
good_users = []
23+
users = User.where('created_at > ?', since).where(bad_user: false); nil
24+
users.each do |u|
2225
flags = Spaminator.new.user_flags(u)
2326
if flags.any?
24-
puts "#{u.id} – #{u.username}#{(u.about || '')[0..100].gsub("\n", '')}"
25-
puts "#{flags.inspect}" if flags.any?
26-
puts
27+
Rails.logger.debug "#{u.id} – #{u.username}#{(u.about || '')[0..100].gsub("\n", '')}"
28+
Rails.logger.debug "#{flags.inspect}" if flags.any?
29+
Rails.logger.debug
2730

2831
u.bad_user!
2932
else
30-
good << u
33+
good_users << "https://coderwall.com/#{u.username}"
3134
end
32-
end
35+
end; nil
3336

34-
puts "Good"
35-
good.each do |e|
36-
puts "#{e.class}:#{e.id}#{e.try(:username) || e.title}"
37+
["Good Users", good_users, "Good Protips", good_protips].flatten.each do |e|
38+
Rails.logger.debug e
3739
end
40+
41+
Rails.logger.info("spam-sweep bad-users=#{users.size - good_users.size}/#{users.size} bad-protips=#{protips.size - good_protips.size}/#{protips.size}")
3842
end
3943
end

0 commit comments

Comments
 (0)