ruboty-twitter_track 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/lib/ruboty/handlers/twitter_track.rb +32 -28
- data/lib/ruboty/twitter_track/stream.rb +9 -7
- data/lib/ruboty/twitter_track/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bcad5f258d6f12adc8bf514bb42b091e9110c73
|
4
|
+
data.tar.gz: feeac45bcda8da737ecd41ba628e274a10b57645
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39c955ee2d2b30aae1ccdf8f853b3f37024bd67e5ff82750627431af3458f3d5a4696f868a8fe5f027e6ac0c4ded17fc1b95817484ade07164f70c997ea95dfd
|
7
|
+
data.tar.gz: ed6ff5dbc00eaf9267c0be105ce3ade7ee99e6c54941b1198c9c5b99318dbc27e4674a064febcff3272743024f3207b157753a3c6b1185c533028c0e8563b008
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Ruboty::TwitterTrack
|
2
2
|
|
3
|
-
Ruboty handler to track
|
3
|
+
Ruboty handler to track certain words in the twitter stream.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -17,18 +17,18 @@ And then execute:
|
|
17
17
|
## Usage
|
18
18
|
|
19
19
|
```
|
20
|
-
> @ruboty track
|
21
|
-
Tracked '
|
20
|
+
> @ruboty twitter track by rubygems
|
21
|
+
@ruboty> Tracked 'rubygems'
|
22
22
|
|
23
23
|
@ruboty> https://twitter.com/haccht/status/123456789
|
24
24
|
@ruboty> https://twitter.com/haccht/status/123456790
|
25
25
|
@ruboty> https://twitter.com/haccht/status/123456791
|
26
26
|
|
27
|
-
> @ruboty
|
28
|
-
@
|
27
|
+
> @ruboty twitter tracking
|
28
|
+
@ruboty> 'rubygems'
|
29
29
|
|
30
|
-
> @ruboty untrack
|
31
|
-
Untracked '
|
30
|
+
> @ruboty twitter untrack by rubygems
|
31
|
+
@ruboty> Untracked 'rubygems'
|
32
32
|
```
|
33
33
|
|
34
34
|
## Env
|
@@ -1,69 +1,73 @@
|
|
1
1
|
module Ruboty
|
2
2
|
module Handlers
|
3
3
|
class TwitterTrack < Base
|
4
|
-
on(/track
|
4
|
+
on(/twitter track by (?<term>.+)\z/,
|
5
5
|
name: 'track',
|
6
|
-
description: 'Track
|
6
|
+
description: 'Track the twitter stream by the certain term.')
|
7
7
|
|
8
|
-
on(/untrack
|
8
|
+
on(/twitter untrack by (?<term>.+)\z/,
|
9
9
|
name: 'untrack',
|
10
|
-
description: 'Untrack
|
10
|
+
description: 'Untrack the twitter stream by the certain term.')
|
11
11
|
|
12
|
-
on(/
|
12
|
+
on(/twitter tracking\z/,
|
13
13
|
name: 'tracking',
|
14
|
-
description: 'List tracking
|
14
|
+
description: 'List tracking terms.')
|
15
15
|
|
16
16
|
def initialize(*args)
|
17
17
|
super
|
18
18
|
|
19
19
|
@stream = Ruboty::TwitterTrack::Stream.new(robot)
|
20
|
-
@stream.start(
|
20
|
+
@stream.start(cache[:message], cache[:terms])
|
21
21
|
end
|
22
22
|
|
23
23
|
def track(message)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
message.reply("Tracked '#{term}'.")
|
30
|
-
end
|
24
|
+
cache[:message] = message.original.except(:robot)
|
25
|
+
|
26
|
+
message[:term].split(',').each do |term|
|
27
|
+
words = term.strip.split(/\s+/).sort
|
28
|
+
cache[:terms].push(words).uniq!
|
31
29
|
end
|
32
30
|
|
33
31
|
begin
|
34
|
-
@stream.restart(
|
32
|
+
@stream.restart(cache[:message], cache[:terms])
|
33
|
+
message.reply("Done.")
|
35
34
|
rescue Twitter::Error::Forbidden
|
36
35
|
message.reply("Unable to verify your credentials.")
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
39
|
def untrack(message)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
message.reply("'#{term}' has not tracked.")
|
47
|
-
end
|
40
|
+
cache[:message] = message.original.except(:robot)
|
41
|
+
|
42
|
+
message[:term].split(',').each do |term|
|
43
|
+
words = term.strip.split(/\s+/).sort
|
44
|
+
cache[:terms].delete(words)
|
48
45
|
end
|
49
46
|
|
50
47
|
begin
|
51
|
-
@stream.restart(
|
48
|
+
@stream.restart(cache[:message], cache[:terms])
|
49
|
+
message.reply("Done.")
|
52
50
|
rescue Twitter::Error::Forbidden
|
53
51
|
message.reply("Unable to verify your credentials.")
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
55
|
def tracking(message)
|
58
|
-
if
|
59
|
-
message.reply("
|
56
|
+
if cache[:terms].empty?
|
57
|
+
message.reply("Tracking no terms.")
|
60
58
|
else
|
61
|
-
|
59
|
+
response = cache[:terms].map { |words| message.reply(words.join(' ') }.join("\n")
|
60
|
+
message.reply(response, code:true)
|
62
61
|
end
|
63
62
|
end
|
64
63
|
|
65
|
-
def
|
66
|
-
robot.brain.data[Ruboty::TwitterTrack::NAMESPACE]
|
64
|
+
def cache
|
65
|
+
unless robot.brain.data[Ruboty::TwitterTrack::NAMESPACE]
|
66
|
+
status = { message: nil, terms: [] }
|
67
|
+
robot.brain.data[Ruboty::TwitterTrack::NAMESPACE] = status
|
68
|
+
end
|
69
|
+
|
70
|
+
robot.brain.data[Ruboty::TwitterTrack::NAMESPACE]
|
67
71
|
end
|
68
72
|
end
|
69
73
|
end
|
@@ -34,20 +34,22 @@ module Ruboty
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def start(terms)
|
37
|
+
def start(message, terms)
|
38
38
|
return if terms.empty?
|
39
39
|
|
40
40
|
Thread.start do
|
41
|
-
|
42
|
-
|
43
|
-
message.reply(u(object))
|
41
|
+
query = terms.map { |w| w.join(' ') }
|
42
|
+
@client.track(*query) do |object|
|
43
|
+
Message.new(message.merge(robot: @robot)).reply(u(object))
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def restart(terms)
|
49
|
-
return start(terms) unless @client.stream
|
50
|
-
|
48
|
+
def restart(message, terms)
|
49
|
+
return start(message, terms) unless @client.stream
|
50
|
+
|
51
|
+
query = terms.map { |w| w.join(' ') }
|
52
|
+
@client.stream.update(params: {:track => query.join(',')})
|
51
53
|
end
|
52
54
|
|
53
55
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-twitter_track
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- haccht
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|