-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtilingol.rb
More file actions
executable file
·60 lines (49 loc) · 1.87 KB
/
Copy pathtilingol.rb
File metadata and controls
executable file
·60 lines (49 loc) · 1.87 KB
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
#!/usr/bin/env ruby
require "rubygems"
require "tweetstream"
require "yaml"
require "json"
require "uri"
require_relative "./peak_detection"
require_relative "./stdout_bell"
require_relative "./jingle_bell"
# CONFIGURATION
@keywords = "gol,gool,goool,golaço"
@languages = ""
@peak_detector = Tilingol::PeakDetection.new(1,10,1.5, true) #frequency window, moving average window, peak threshold
@bell = Tilingol::StdoutBell.new # or JingleBell.new | use the class according with the bell wanted
@magic_word = "toqueosinopequenino" # tweet with this word + a tracker keyword to ring the bell anyway
# END OF CONFIGURATION
unless ENV['TW_CONSUMER_KEY']
# Will load credentials.yml, make sure it's there
# This must to be used only for development environment
@oauth = YAML.load_file(File.expand_path("./config/credentials.yml"))
ENV['TW_CONSUMER_KEY'] = @oauth["consumer_key"]
ENV['TW_CONSUMER_SECRET'] = @oauth["consumer_secret"]
ENV['TW_OAUTH_TOKEN'] = @oauth["access_token"]
ENV['TW_OAUTH_TOKEN_SECRET'] = @oauth["access_token_secret"]
end
# configure tweetstream instance
TweetStream.configure do |config|
config.consumer_key = ENV['TW_CONSUMER_KEY']
config.consumer_secret = ENV['TW_CONSUMER_SECRET']
config.oauth_token = ENV['TW_OAUTH_TOKEN']
config.oauth_token_secret = ENV['TW_OAUTH_TOKEN_SECRET']
config.auth_method = :oauth
end
@client = TweetStream::Client.new
@client.on_error do |message|
puts "ERROR: #{message}"
end
@client.on_enhance_your_calm do
puts "Calm down"
end
@client.on_limit do |skip_count|
puts "You lost #{skip_count} tweets"
end
puts "Starting to track: #{@keywords}...\nLanguages: #{@languages}"
@client.filter(:track => @keywords, :language => @languages) do |status|
@peak_detector.collect_frequency
@bell.ring! if @peak_detector.is_this_a_peak? || status.text.index(@magic_word)
#puts status.text
end