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
|
# File 'lib/twit_sucker.rb', line 7
def self.run(path, *magic_words)
if !Dir.exists?(path)
Dir.mkdir(path)
end
Dir.chdir(path)
EventMachine::run {
stream = Twitter::JSONStream.connect(
:path => '/1/statuses/filter.json',
:auth => 'SFilimonova:QA3s4NLT',
:method => 'POST',
:content => 'track=' + magic_words.join(',')
)
i = 100
stream.each_item do |item|
file = File.open(Time.now.to_s+i.to_s, 'w')
file << JSON.parse(item)['text']
file.close
if i<999
i+=1
else
i = 100
end
end
trap('TERM') {
stream.stop
EventMachine.stop if EventMachine.reactor_running?
}
}
end
|