favt 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/favt +7 -0
- data/lib/favt.rb +4 -117
- data/lib/favt/client.rb +75 -0
- data/lib/favt/render.rb +79 -0
- data/lib/favt/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22fdcc2d77b7cb92dfaf41890e77176c51b6ec12
|
4
|
+
data.tar.gz: 3c52f7271410151fb3dd8711994c48ade552a22c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6bfb7625e755c048a71ccc79b9495e695b52026eb775699a4beb225e8fa25452b02899ec10c7e27f345e1e1e2b6edba2a9afa0d4e7713931ee12e22e1da5199
|
7
|
+
data.tar.gz: c7e0a7d90ac006acca901e260cc2c3ec816f443012aa0ec06a0c5dcf78089550b7f79347388d2a12c7517f7d60efb09f52d4a313235f7c8bcbef8d374f9d801f
|
data/bin/favt
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
2
3
|
|
3
4
|
require 'optparse'
|
4
5
|
require 'colorize'
|
@@ -75,6 +76,12 @@ client:
|
|
75
76
|
consumer_secret: "Your Consumer Secret Key"
|
76
77
|
access_token: "Your Access Token"
|
77
78
|
access_token_secret: "Your Access Token Secret"
|
79
|
+
|
80
|
+
custom_render:
|
81
|
+
users: "■"
|
82
|
+
screen_name: "#\{post.user.screen_name}\n"
|
83
|
+
post_text: "#\{post.text}"
|
84
|
+
post_url: "#\{post.url}"
|
78
85
|
|
79
86
|
users:
|
80
87
|
- "esehara"
|
data/lib/favt.rb
CHANGED
@@ -1,122 +1,9 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require "favt/version"
|
3
|
-
require "
|
4
|
-
require "
|
5
|
-
require "yaml"
|
3
|
+
require "favt/client"
|
4
|
+
require "favt/render"
|
6
5
|
|
7
6
|
module Favt
|
8
|
-
|
9
|
-
|
10
|
-
keys = @config["client"]
|
11
|
-
@client = Twitter::REST::Client.new do |config|
|
12
|
-
config.consumer_key = keys["consumer_key"]
|
13
|
-
config.consumer_secret = keys["consumer_secret"]
|
14
|
-
config.access_token = keys["access_token"]
|
15
|
-
config.access_token_secret = keys["access_token_secret"]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(options)
|
20
|
-
yaml_file = options["config_file"] || "config.yaml"
|
21
|
-
@render = options["render"] || Render
|
22
|
-
@options = options
|
23
|
-
@config = YAML.load_file(yaml_file)
|
24
|
-
|
25
|
-
self.init_client()
|
26
|
-
end
|
27
|
-
|
28
|
-
def favorites_from_user
|
29
|
-
users = self.target_users
|
30
|
-
return users.flat_map do |user|
|
31
|
-
@client.favorites user
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def take(set_fav_posts)
|
36
|
-
show_count = @options["show_count"].to_i || 0
|
37
|
-
if show_count != 0
|
38
|
-
return set_fav_posts.take(show_count)
|
39
|
-
end
|
40
|
-
return set_fav_posts
|
41
|
-
end
|
42
|
-
|
43
|
-
def target_users
|
44
|
-
if !@options["user"]
|
45
|
-
return @config["users"]
|
46
|
-
end
|
47
|
-
return [@options["user"]]
|
48
|
-
end
|
49
|
-
|
50
|
-
def favorite_posts
|
51
|
-
show_fav_posts = self.to_set(self.favorites_from_user.sort do
|
52
|
-
|prev_post, next_post| next_post.id <=> prev_post.id
|
53
|
-
end)
|
54
|
-
|
55
|
-
return self.take(show_fav_posts)
|
56
|
-
end
|
57
|
-
|
58
|
-
def to_set(favorites)
|
59
|
-
favorites_dict = {}
|
60
|
-
favorites.each do |favorite|
|
61
|
-
if !(favorites_dict.key? favorite.id)
|
62
|
-
favorites_dict[favorite.id] = {
|
63
|
-
"users" => 1, "post" => favorite}
|
64
|
-
else
|
65
|
-
favorites_dict[favorite.id]["users"] += 1
|
66
|
-
end
|
67
|
-
end
|
68
|
-
return favorites_dict
|
69
|
-
end
|
70
|
-
|
71
|
-
def render
|
72
|
-
self.favorite_posts.each do |_, favorite|
|
73
|
-
print @render.new(favorite, @options).to_s
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
class Render
|
79
|
-
def initialize(favorite, options)
|
80
|
-
@users = favorite["users"]
|
81
|
-
@post = favorite["post"]
|
82
|
-
@options = options
|
83
|
-
end
|
84
|
-
|
85
|
-
def render_users
|
86
|
-
render = "■"
|
87
|
-
|
88
|
-
if !@options["no_color"]
|
89
|
-
render = render.red
|
90
|
-
end
|
91
|
-
|
92
|
-
@users.times do
|
93
|
-
print render
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def post_colorize(render_dict)
|
98
|
-
if !@options["no_color"]
|
99
|
-
render_dict[:screen_name] = render_dict[:screen_name].green.bold
|
100
|
-
render_dict[:post_url] = render_dict[:post_url].blue
|
101
|
-
end
|
102
|
-
return render_dict
|
103
|
-
end
|
104
|
-
|
105
|
-
def render_post
|
106
|
-
post = @post
|
107
|
-
|
108
|
-
post_template = {
|
109
|
-
screen_name: "[#{post.user.screen_name}] ",
|
110
|
-
post_text: "#{post.text}\n",
|
111
|
-
post_url: "#{post.url}\n",
|
112
|
-
}
|
113
|
-
|
114
|
-
self.post_colorize(post_template).values.join
|
115
|
-
end
|
116
|
-
|
117
|
-
def to_s
|
118
|
-
self.render_users
|
119
|
-
self.render_post
|
120
|
-
end
|
121
|
-
end
|
7
|
+
include Client
|
8
|
+
include Render
|
122
9
|
end
|
data/lib/favt/client.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "twitter"
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
module Client
|
6
|
+
class TwitterClient
|
7
|
+
def init_client
|
8
|
+
keys = @config["client"]
|
9
|
+
@client = Twitter::REST::Client.new do |config|
|
10
|
+
config.consumer_key = keys["consumer_key"]
|
11
|
+
config.consumer_secret = keys["consumer_secret"]
|
12
|
+
config.access_token = keys["access_token"]
|
13
|
+
config.access_token_secret = keys["access_token_secret"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(options)
|
18
|
+
yaml_file = options["config_file"] || "config.yaml"
|
19
|
+
@render = options["render"] || Favt::Render
|
20
|
+
@options = options
|
21
|
+
@config = YAML.load_file(yaml_file)
|
22
|
+
self.init_client
|
23
|
+
end
|
24
|
+
|
25
|
+
def favorites_from_user
|
26
|
+
users = self.target_users
|
27
|
+
return users.flat_map do |user|
|
28
|
+
@client.favorites user
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def take(set_fav_posts)
|
33
|
+
show_count = @options["show_count"].to_i || 0
|
34
|
+
if show_count != 0
|
35
|
+
return set_fav_posts.take(show_count)
|
36
|
+
end
|
37
|
+
return set_fav_posts
|
38
|
+
end
|
39
|
+
|
40
|
+
def target_users
|
41
|
+
if !@options["user"]
|
42
|
+
return @config["users"]
|
43
|
+
end
|
44
|
+
return [@options["user"]]
|
45
|
+
end
|
46
|
+
|
47
|
+
def favorite_posts
|
48
|
+
show_fav_posts = self.to_set(self.favorites_from_user.sort do
|
49
|
+
|prev_post, next_post| next_post.id <=> prev_post.id
|
50
|
+
end)
|
51
|
+
|
52
|
+
return self.take(show_fav_posts)
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_set(favorites)
|
56
|
+
favorites_dict = {}
|
57
|
+
favorites.each do |favorite|
|
58
|
+
if !(favorites_dict.key? favorite.id)
|
59
|
+
favorites_dict[favorite.id] = {
|
60
|
+
"users" => 1, "post" => favorite}
|
61
|
+
else
|
62
|
+
favorites_dict[favorite.id]["users"] += 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return favorites_dict
|
66
|
+
end
|
67
|
+
|
68
|
+
def render
|
69
|
+
self.favorite_posts.each do |_, favorite|
|
70
|
+
print @render.new(favorite, @options, @config).to_s
|
71
|
+
print "\n"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/favt/render.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "colorize"
|
3
|
+
|
4
|
+
module Render
|
5
|
+
class Render
|
6
|
+
def initialize(favorite, options, config)
|
7
|
+
|
8
|
+
@favorite = favorite
|
9
|
+
@options = options
|
10
|
+
@config = config
|
11
|
+
|
12
|
+
self.init_custom_render
|
13
|
+
.repack
|
14
|
+
end
|
15
|
+
|
16
|
+
def repack
|
17
|
+
post = @favorite["post"]
|
18
|
+
|
19
|
+
@render = {}
|
20
|
+
@render[:users] = @origin_render[:users] * @favorite["users"]
|
21
|
+
@render[:screen_name] = @origin_render[:screen_name]
|
22
|
+
.sub('#{post.user.screen_name}', post.user.screen_name)
|
23
|
+
@render[:post_text] = @origin_render[:post_text]
|
24
|
+
.sub('#{post.text}', post.text)
|
25
|
+
@render[:post_url] = @origin_render[:post_url]
|
26
|
+
.sub('#{post.url}', post.url.to_s)
|
27
|
+
end
|
28
|
+
|
29
|
+
def init_custom_render
|
30
|
+
custom_render = @config["custom_render"]
|
31
|
+
|
32
|
+
# First Initialize Values
|
33
|
+
|
34
|
+
users_str = '■'
|
35
|
+
screen_name_str = '[#{post.user.screen_name}]\n'
|
36
|
+
post_text_str = '#{post.text}\n'
|
37
|
+
post_url_str = '#{post.url}\n'
|
38
|
+
|
39
|
+
if custom_render
|
40
|
+
users_str = custom_render["users"] || users_str
|
41
|
+
screen_name_str = custom_render["screen_name"] || screen_name_str
|
42
|
+
post_text_str = custom_render["post_text"] || post_text_str
|
43
|
+
post_url_str = custom_render["post_url"] || post_url_str
|
44
|
+
end
|
45
|
+
|
46
|
+
@origin_render = {
|
47
|
+
users: users_str,
|
48
|
+
screen_name: screen_name_str,
|
49
|
+
post_text: post_text_str,
|
50
|
+
post_url: post_url_str
|
51
|
+
}
|
52
|
+
return self
|
53
|
+
end
|
54
|
+
|
55
|
+
def user_colorize
|
56
|
+
if !@options["no_color"]
|
57
|
+
@render[:users] = @render[:users].red
|
58
|
+
end
|
59
|
+
return self
|
60
|
+
end
|
61
|
+
|
62
|
+
def post_colorize
|
63
|
+
if !@options["no_color"]
|
64
|
+
@render[:screen_name] = @render[:screen_name].green.bold
|
65
|
+
@render[:post_url] = @render[:post_url].blue
|
66
|
+
end
|
67
|
+
return @render
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_s
|
71
|
+
self
|
72
|
+
.user_colorize
|
73
|
+
.post_colorize
|
74
|
+
.values.join
|
75
|
+
.sub("\\n", "\n")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
data/lib/favt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: favt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- esehara shigeo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|
@@ -83,6 +83,8 @@ files:
|
|
83
83
|
- config.sample.yaml
|
84
84
|
- favt.gemspec
|
85
85
|
- lib/favt.rb
|
86
|
+
- lib/favt/client.rb
|
87
|
+
- lib/favt/render.rb
|
86
88
|
- lib/favt/version.rb
|
87
89
|
homepage: ''
|
88
90
|
licenses:
|