favt 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 549e07baa82e2556c6c5d4b71fe75079deca3878
4
+ data.tar.gz: 6cf4cdbbb90778f743020f7befb4a01161f1521e
5
+ SHA512:
6
+ metadata.gz: ab5b66c40f197b272551609659ebb9556a29a2851ff1d4de0aeadaa5e37d05e8d9102bf1164131a41802bab6626409129ec097c95a522893b17a9c47bd92cf3f
7
+ data.tar.gz: b8b8a0d389761a8c9376d07f622b4581459609d82990a69e01215d1fa86cb5b1aa1629d0fb1face7aae7de610ea850d845f6af5b1d69dd3cb83c2e38a5b851b7
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ config.yaml
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in favt.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 esehara shigeo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Favt
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'favt'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install favt
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/favt/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/favt ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'colorize'
5
+ require 'favt'
6
+ require 'twitter'
7
+
8
+ def option_parse
9
+ options = {}
10
+ OptionParser.new do |opts|
11
+
12
+ opts.banner = "Usage: Twitter Favorite Reader"
13
+
14
+ opts.on("-s N", "--show-count N", Integer, "Show Favorites (default: all)") do |n|
15
+ options["show_count"] = n
16
+ end
17
+
18
+ opts.on("-u USER", "--user USER", String, "Read posts target favorited") do |user|
19
+ options["user"] = user
20
+ end
21
+
22
+ end.parse!
23
+ return options
24
+ end
25
+
26
+ begin
27
+ ft = Favt::TwitterClient.new(option_parse)
28
+ ft.render()
29
+ rescue Twitter::Error::TooManyRequests => e
30
+ print "Error!!".light_red
31
+ print " -- ".light_green
32
+ print "Twitter API, Too Many Requests. Perhaps, Rate Limit Exceeded. \n".uncolorize
33
+ end
@@ -0,0 +1,18 @@
1
+ lient:
2
+ consumer_key: "Your Consumer Key"
3
+ consumer_secret: "Your Consumer Secret Key"
4
+ access_token: "Your Access Token"
5
+ access_token_secret: "Your Access Token Secret"
6
+
7
+ users:
8
+ - "todesking"
9
+ - "sudo_vi"
10
+ - "sanjuusan"
11
+ - "DHC_"
12
+ - "toby_net"
13
+ - "doom_k"
14
+ - "pornanime"
15
+ - "tadsan"
16
+ - "ntddk"
17
+ - "drillbits"
18
+ - "mizchi"
data/favt.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'favt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "favt"
8
+ spec.version = Favt::VERSION
9
+ spec.authors = ["esehara shigeo"]
10
+ spec.email = ["esehara@gmail.com"]
11
+ spec.summary = %q{Twitter Cliant for Favorite}
12
+ spec.description = %q{Twitter Client for post favorited by users}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ["favt"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "twitter"
22
+ spec.add_dependency "colorize"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
data/lib/favt.rb ADDED
@@ -0,0 +1,87 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "favt/version"
3
+ require "twitter"
4
+ require "colorize"
5
+ require "yaml"
6
+
7
+ module Favt
8
+ class TwitterClient
9
+
10
+ def init_client()
11
+ keys = @config["client"]
12
+ @client = Twitter::REST::Client.new do |config|
13
+ config.consumer_key = keys["consumer_key"]
14
+ config.consumer_secret = keys["consumer_secret"]
15
+ config.access_token = keys["access_token"]
16
+ config.access_token_secret = keys["access_token_secret"]
17
+ end
18
+ end
19
+
20
+ def initialize(options)
21
+ yaml_file = options["config_file"] || "config.yaml"
22
+
23
+ @options = options
24
+ @config = YAML.load_file(yaml_file)
25
+
26
+ self.init_client()
27
+ end
28
+
29
+ def favorites_from_user()
30
+ users = self.target_users
31
+ favorites = users.map do |user|
32
+ @client.favorites user
33
+ end.flatten!
34
+ end
35
+
36
+ def take(set_fav_posts)
37
+ show_count = @options["show_count"].to_i || 0
38
+ if show_count != 0
39
+ set_fav_posts.take(show_count)
40
+ end
41
+ return set_fav_posts
42
+ end
43
+
44
+ def target_users()
45
+ if !@options["user"]
46
+ return @config["users"]
47
+ end
48
+ return [@options["user"]]
49
+ end
50
+
51
+ def favorite_posts()
52
+
53
+ show_fav_posts = self.to_set(self.favorites_from_user.sort do
54
+ |prev_post, next_post| next_post.id <=> prev_post.id
55
+ end)
56
+
57
+ return self.take(show_fav_posts)
58
+ end
59
+
60
+ def to_set(favorites)
61
+ favorites_dict = {}
62
+ favorites.each do |favorite|
63
+ if !(favorites_dict.key? favorite.id)
64
+ favorites_dict[favorite.id] = {
65
+ "users" => 1, "post" => favorite}
66
+ else
67
+ favorites_dict[favorite.id]["users"] += 1
68
+ end
69
+ end
70
+ return favorites_dict
71
+ end
72
+
73
+ def render()
74
+
75
+ self.favorite_posts.each do |_, favorite|
76
+ favorite["users"].times do
77
+ print "■".red
78
+ end
79
+
80
+ post = favorite["post"]
81
+ print "[#{post.user.screen_name}] ".green.bold
82
+ print "#{post.text}\n".uncolorize
83
+ print "#{post.url}\n".blue
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module Favt
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: favt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - esehara shigeo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: twitter
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Twitter Client for post favorited by users
70
+ email:
71
+ - esehara@gmail.com
72
+ executables:
73
+ - favt
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/favt
83
+ - config.sample.yaml
84
+ - favt.gemspec
85
+ - lib/favt.rb
86
+ - lib/favt/version.rb
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Twitter Cliant for Favorite
111
+ test_files: []