-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
62 lines (50 loc) · 1.61 KB
/
app.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
# -*- coding: utf-8 -*-
require 'pp'
require 'yaml'
require 'bundler'
Bundler.require
config = YAML.load_file('config.yml')
Pushover.configure do |pushover_config|
pushover_config.user = config["user_token"]
pushover_config.token = config["app_token"]
pushover_config.device = config["device"]
end
SOUND = config["sound"]
PRIORITY = config["priority"]
EventMachine::run do
userstream = {
:host => "userstream.twitter.com",
:path => "/2/user.json?include_followings_activity=true",
:ssl => true,
:oauth => {
:consumer_key => config["consumer_key"],
:consumer_secret => config["consumer_secret"],
:access_key => config["access_token"],
:access_secret => config["access_secret"]
}
}
stream = Twitter::JSONStream.connect(userstream)
stream.each_item do |item|
data = Yajl::Parser.parse(item)
# pp data
if data["event"]
source = data["source"]
target = data["target"]
object = data["target_object"]
case data["event"]
when "favorite"
puts "@%s (→☆) @%s: %s" % [source["screen_name"], object["user"]["screen_name"], object["text"]]
Pushover.notification(
message: "@%s (→☆) @%s: %s" % [source["screen_name"], object["user"]["screen_name"], object["text"]],
title: "kosenconf080tokyo",
url: '',
sound: SOUND,
priority: PRIORITY,
)
end
end
end
stream.on_error do |message|
exit
end
end