-
Notifications
You must be signed in to change notification settings - Fork 1
/
ocorreto.rb
68 lines (59 loc) · 2.41 KB
/
ocorreto.rb
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
# encoding: utf-8
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
require 'oauth'
def search(url, wrong, correct)
begin
# parse the url we want to access
uri = URI.parse(url)
# creating a request object
req = Net::HTTP.get(uri)
req = req.to_s
hash = JSON.parse(req)
access = login
hash["results"].each do |tweet|
puts tweet["from_user"]
puts tweet["id"]
last = reply(tweet["from_user"], access, wrong, correct)
if last.is_a? (Net::HTTPOK)
@last = (tweet["id"] rescue @last)
end
sleep(90)
end
rescue
end
end
def login
consumer = OAuth::Consumer.new("EA9xBRiRKA0cv43CZgA8hw", "Aq1gyrKnliJVpLxwFqGmzoD3moP8BDKqVWcs2rS2E", {:site => "http://api.twitter.com", :scheme => :header})
# now create the access token object from passed values
token_hash = { :oauth_token => '348876777-JOhzzcJg8SmF8Y9s8G5Fhtxsxvthb2Yur8dRamSD',
:oauth_token_secret => 'fMQaPBD8aNRVFhz43u8i5znQazHMiZfaZHOURNY'
}
access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
end
def reply(from, access_token, correct)
response = access_token.request(:post, 'http://api.twitter.com/1/statuses/update.json', {:status => "Ei @#{from}, sabia que a forma certa de escrever '#{wrong}' é '#{correct}'? Siga-me para conhecer outros erros comuns."}, {'Content-Type' => 'application/xml' })
puts response.class
response.class
end
@last = 107838698829258753
keywords = []
keywords << {:word => "infelismente", :correct => "infeliZmente", :last => @last}
keywords << {:word => "ancioso", :correct => "anSioso", :last => @last}
keywords << {:word => "falcidade", :correct => "falSidade", :last => @last}
keywords << {:word => "enchergar", :correct => "enXergar", :last => @last}
keywords << {:word => "sombrancelhas", :correct => "sobrancelhas", :last => @last}
keywords << {:word => "esplicar", :correct => "eXplicar", :last => @last}
keywords << {:word => "encomodar", :correct => "Incomodar", :last => @last}
keywords << {:word => "geito", :correct => "Jeito", :last => @last}
keywords << {:word => "concerteza", :correct => "com certeza", :last => @last}
keywords << {:word => "simplismente", :correct => "simplEsmente", :last => @last}
keywords.shuffle!
while true do
keywords.each do |w|
search("http://search.twitter.com/search.json?q=#{w[:word]}&since_id=#{w[:last]}", "#{w[:word]}", "#{w[:correct]}")
w[:last] = @last
end
end