favt 0.0.7 → 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/bin/favt +34 -10
- data/lib/favt.rb +49 -11
- data/lib/favt/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: 8ea6e7884c78dc9a87a2df33da350b76f53ec657
|
4
|
+
data.tar.gz: a16bae914515ca427b9b681bbfeddc4f4850388b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 203442991f08bf557e022fcacd12ab0b8c281596f8c35921df5ce06e2cccaba47fc64b159a1111148c84b43b2aa98cf8769a9eeb82aa39525ede110f599d2019
|
7
|
+
data.tar.gz: 98b136059f648def0998f40d8e0cee2438415a0abca86accd9429b693e275c5a3aa0d91459f9e55eeb161f27c1df7670c6371d7fc9a38e374054c614f08f2003
|
data/bin/favt
CHANGED
@@ -6,7 +6,7 @@ require 'favt'
|
|
6
6
|
require 'twitter'
|
7
7
|
|
8
8
|
def option_parse
|
9
|
-
options = {}
|
9
|
+
options = {"no_color" => false}
|
10
10
|
OptionParser.new do |opts|
|
11
11
|
|
12
12
|
opts.banner = "Usage: Twitter Favorite Reader"
|
@@ -23,24 +23,48 @@ def option_parse
|
|
23
23
|
"Set any config yaml file (default:config.yaml)") do |file|
|
24
24
|
options["config_file"] = file
|
25
25
|
end
|
26
|
+
|
27
|
+
opts.on("--no-color", "use coloring console") do
|
28
|
+
options["no_color"] = true
|
29
|
+
end
|
26
30
|
end.parse!
|
27
31
|
return options
|
28
32
|
end
|
29
33
|
|
30
|
-
def error_print(title)
|
31
|
-
|
32
|
-
|
34
|
+
def error_print(title, options)
|
35
|
+
|
36
|
+
error_template = {
|
37
|
+
error_title: "Error!!",
|
38
|
+
error_line: " -- "
|
39
|
+
}
|
40
|
+
|
41
|
+
if !options["no_color"]
|
42
|
+
error_template[:error_title] = error_template[:error_title].red
|
43
|
+
error_template[:error_line] = error_template[:error_line].light_green
|
44
|
+
end
|
45
|
+
|
46
|
+
error_template.each_value { |value| print value}
|
33
47
|
print title.uncolorize
|
34
48
|
end
|
35
49
|
|
36
50
|
|
37
|
-
begin
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
51
|
+
begin
|
52
|
+
|
53
|
+
options = option_parse
|
54
|
+
|
55
|
+
ft = Favt::TwitterClient.new(options)
|
56
|
+
ft.render
|
57
|
+
|
58
|
+
rescue Twitter::Error::TooManyRequests
|
59
|
+
|
60
|
+
message = "Twitter API, Too Many Requests. Perhaps, Rate Limit Exceeded. \n"
|
61
|
+
error_print(message, options)
|
62
|
+
|
42
63
|
rescue Errno::ENOENT
|
43
|
-
|
64
|
+
|
65
|
+
message = "Config file is not found.\n"
|
66
|
+
error_print(message, options)
|
67
|
+
|
44
68
|
print <<EOF
|
45
69
|
|
46
70
|
Config file examples (config.yaml)
|
data/lib/favt.rb
CHANGED
@@ -18,7 +18,7 @@ module Favt
|
|
18
18
|
|
19
19
|
def initialize(options)
|
20
20
|
yaml_file = options["config_file"] || "config.yaml"
|
21
|
-
|
21
|
+
@render = options["render"] || Render
|
22
22
|
@options = options
|
23
23
|
@config = YAML.load_file(yaml_file)
|
24
24
|
|
@@ -27,9 +27,9 @@ module Favt
|
|
27
27
|
|
28
28
|
def favorites_from_user
|
29
29
|
users = self.target_users
|
30
|
-
|
30
|
+
return users.flat_map do |user|
|
31
31
|
@client.favorites user
|
32
|
-
end
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def take(set_fav_posts)
|
@@ -70,15 +70,53 @@ module Favt
|
|
70
70
|
|
71
71
|
def render
|
72
72
|
self.favorite_posts.each do |_, favorite|
|
73
|
-
favorite
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
81
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
|
82
120
|
end
|
83
121
|
end
|
84
122
|
end
|
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.1.1
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|