Last active
October 15, 2016 14:55
-
-
Save zwpp/2eb2c1424633d3a072caf12f2bc3168d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'uri' | |
require 'zbar' | |
require 'mini_magick' | |
require 'twitter' | |
SEARCH_KEYWORD = "" | |
CONSUMER_KEY = "" | |
CONSUMER_SECRET = "" | |
ACCESS_TOKEN = "" | |
ACCESS_TOKEN_SECRET = "" | |
module QRDecoder | |
extend self | |
def decode(data) | |
img = MiniMagick::Image.read(data) | |
img.format('PGM') | |
pgm = img.to_blob | |
res = ZBar::Image.from_pgm(pgm).process | |
res.map &:data | |
end | |
def qrdecode_from_uri(uri) | |
decode(Net::HTTP.get(URI.parse(uri))) | |
end | |
end | |
def spam?(texts) | |
texts.any? {|t| t.include?("line.me") } | |
end | |
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 | |
media_tweets = client.search(SEARCH_KEYWORD, result_type: "recent", count:100).select do |tw| | |
tw.media? | |
end | |
spam_tweets = media_tweets.select do |tw| | |
tw.media.map(&:media_url).map(&:to_s).any? do |uri| | |
spam? QRDecoder::qrdecode_from_uri(uri) | |
end | |
end | |
p spam_tweets.map(&:full_text) | |
client.block spam_tweets.map(&:user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment