ytopics 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/bin/ytopics +8 -0
- data/lib/ytopics.rb +63 -0
- data/lib/ytopics/version.rb +3 -0
- data/ytopics.gemspec +19 -0
- metadata +56 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Keita Mori
|
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,33 @@
|
|
1
|
+
# Ytopics
|
2
|
+
|
3
|
+
View yahoo(.co.jp) topics on your terminal.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ytopics'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ytopics
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
$ ytopics
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
30
|
+
|
31
|
+
## Inspired by
|
32
|
+
|
33
|
+
[仕事中、一瞬の隙も見逃さずに情報収集できるRubyワンライナーとスクリプト - maeharinの日記](http://d.hatena.ne.jp/maeharin/20130110/p1)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/ytopics
ADDED
data/lib/ytopics.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "ytopics/version"
|
2
|
+
require 'open-uri'
|
3
|
+
require 'readline'
|
4
|
+
|
5
|
+
module Ytopics
|
6
|
+
class Topic
|
7
|
+
attr_accessor :title, :body, :url
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
yield self
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
if self.body.nil?
|
15
|
+
flg = false
|
16
|
+
open(self.url, "r:euc-jp") do |f|
|
17
|
+
f.read.encode("utf-8").scan(/<!--HBODY-->(.+?)</) {|m|self.body = m.first}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
puts "<#{self.title}>"
|
21
|
+
puts self.body
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
@@topics ||= []
|
27
|
+
|
28
|
+
def start
|
29
|
+
puts "type `exit` to end ytopics"
|
30
|
+
open('http://www.yahoo.co.jp') do |f|
|
31
|
+
f.read.scan(/topics.+?\*-([^<]+?)</) do |m|
|
32
|
+
next if /backnumber|photograph/ =~ m.first
|
33
|
+
|
34
|
+
ary = m.first.split('">')
|
35
|
+
@@topics << Topic.new do |t|
|
36
|
+
t.url = ary[0]
|
37
|
+
t.title = ary[1]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
display
|
43
|
+
|
44
|
+
while buf = Readline.readline("ytopics> ", false)
|
45
|
+
line = buf.strip
|
46
|
+
break if line == 'exit'
|
47
|
+
unless /^[0-9]+$/ =~ line && @@topics.length > line.to_i
|
48
|
+
puts "Command not found"
|
49
|
+
next
|
50
|
+
end
|
51
|
+
@@topics[line.to_i].show
|
52
|
+
display
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def display
|
57
|
+
@@topics.each_with_index do |t, idx|
|
58
|
+
puts "[#{idx}] #{t.title}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/ytopics.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ytopics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "ytopics"
|
8
|
+
gem.version = Ytopics::VERSION
|
9
|
+
gem.authors = ["Keita Mori"]
|
10
|
+
gem.email = ["keita011@gmail.com"]
|
11
|
+
gem.description = "View yahoo(.co.jp) topics command."
|
12
|
+
gem.summary = "View yahoo(.co.jp) topics command."
|
13
|
+
gem.homepage = "http://github.com/dforest/ytopics"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ytopics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Keita Mori
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-12 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: View yahoo(.co.jp) topics command.
|
15
|
+
email:
|
16
|
+
- keita011@gmail.com
|
17
|
+
executables:
|
18
|
+
- ytopics
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/ytopics
|
29
|
+
- lib/ytopics.rb
|
30
|
+
- lib/ytopics/version.rb
|
31
|
+
- ytopics.gemspec
|
32
|
+
homepage: http://github.com/dforest/ytopics
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.24
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: View yahoo(.co.jp) topics command.
|
56
|
+
test_files: []
|