nogizaka_blog 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/nogizaka_blog +3 -0
- data/lib/nogizaka_blog/amazing.rb +114 -0
- data/lib/nogizaka_blog/cli.rb +27 -0
- data/lib/nogizaka_blog/core_ext.rb +15 -0
- data/lib/nogizaka_blog/member.rb +3 -0
- data/lib/nogizaka_blog/version.rb +3 -0
- data/lib/nogizaka_blog.rb +5 -0
- data/nogizaka_blog.gemspec +24 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea0a9f704e2faf48c660bebcaefbfb7793b630da
|
4
|
+
data.tar.gz: 6a183503c5aa54db0e3c2bf20852de568b58d138
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a90f802fd94b5b9c0ee90d1da098ffbdb788d38627c46d811e282feafc6eb3da32be438cf1cfb54003d006f14d4d4fbf296b911b445a1ffd691a7a22e4b3d078
|
7
|
+
data.tar.gz: aba40c4546624000b4f698ee6515412e54899d957d3c88ca832d2a3518a6d266cbcac29fd0923e0b4cd88add7326d2ffac6fe89fe14f77a08ff3bd9b4f2791b3
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 hachy
|
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,29 @@
|
|
1
|
+
# NogizakaBlog
|
2
|
+
|
3
|
+
Get the number of comments and articles per month from Nogizaka46's blog
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'nogizaka_blog'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install nogizaka_blog
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
$ ruby nogizaka_blog -m 201405
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/nogizaka_blog/fork )
|
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 a new Pull Request
|
data/Rakefile
ADDED
data/bin/nogizaka_blog
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module NogizakaBlog
|
6
|
+
class Amazing
|
7
|
+
using Extentions
|
8
|
+
|
9
|
+
def initialize(yearmonth)
|
10
|
+
@yearmonth = yearmonth
|
11
|
+
@member_size = MEMBER.size
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :member_size
|
15
|
+
|
16
|
+
def scraping
|
17
|
+
get_max_page
|
18
|
+
@member_max.each_with_index do |(name, max), idx|
|
19
|
+
@comment = []
|
20
|
+
|
21
|
+
# @comment = 0 when redirected
|
22
|
+
if max == -1
|
23
|
+
@comment << 0
|
24
|
+
elsif max == 0
|
25
|
+
url = "http://blog.nogizaka46.com/#{name}/?d=#{@yearmonth}"
|
26
|
+
get_comment_size(url)
|
27
|
+
else
|
28
|
+
(1..max).each do |n|
|
29
|
+
url = "http://blog.nogizaka46.com/#{name}/?p=#{n}&d=#{@yearmonth}"
|
30
|
+
get_comment_size(url)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if max == -1
|
35
|
+
article = 0
|
36
|
+
else
|
37
|
+
article = @comment.length
|
38
|
+
end
|
39
|
+
|
40
|
+
yield name, @comment.sum, article, idx
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def run
|
47
|
+
puts "#{@yearmonth[0..3]}/#{@yearmonth[4..5]}"
|
48
|
+
header = display_format('name', 'comment', 'article')
|
49
|
+
puts header
|
50
|
+
puts '-' * header.size
|
51
|
+
scraping do |name, comment, article, _|
|
52
|
+
puts display_format("#{name.to_kanji}(#{name})", comment, article)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def gen_json
|
57
|
+
last = @member_size - 1
|
58
|
+
print "["
|
59
|
+
scraping do |name, comment, article, idx|
|
60
|
+
if idx == last
|
61
|
+
print "{\"name\": \"#{name.to_kanji}\", \"comment\": #{comment}, \"article\": #{article}}"
|
62
|
+
else
|
63
|
+
print "{\"name\": \"#{name.to_kanji}\", \"comment\": #{comment}, \"article\": #{article}},"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
print "]"
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_max_page
|
70
|
+
nbsp = Nokogiri::HTML(' ').text
|
71
|
+
@member_max = []
|
72
|
+
|
73
|
+
MEMBER.keys.each do |name|
|
74
|
+
url = "http://blog.nogizaka46.com/#{name}/?d=#{@yearmonth}"
|
75
|
+
response = Net::HTTP.get_response(URI.parse(url))
|
76
|
+
|
77
|
+
# Be redirected if it doesn't exist @yearmonth.
|
78
|
+
case response
|
79
|
+
when Net::HTTPSuccess
|
80
|
+
doc = Nokogiri::HTML(open(url))
|
81
|
+
paginate_class = doc.css('.paginate:first a:nth-last-child(2)')
|
82
|
+
if paginate_class.empty?
|
83
|
+
num = 0
|
84
|
+
else
|
85
|
+
paginate_class.each do |link|
|
86
|
+
num = link.content
|
87
|
+
end
|
88
|
+
num.gsub!(nbsp, '')
|
89
|
+
end
|
90
|
+
when Net::HTTPRedirection
|
91
|
+
num = -1
|
92
|
+
end
|
93
|
+
|
94
|
+
@member_max << [name, num.to_i]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_comment_size(url)
|
99
|
+
doc = Nokogiri::HTML(open(url))
|
100
|
+
doc.css('.entrybottom a:last').each do |link|
|
101
|
+
link.content.scan(/\d+/) { |c| @comment << c }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def display_format(name, comment, article)
|
106
|
+
name_length = 28 - full_width_count(name)
|
107
|
+
[name.ljust(name_length), comment.to_s.rjust(7), article.to_s.rjust(7)].join(' | ')
|
108
|
+
end
|
109
|
+
|
110
|
+
def full_width_count(string)
|
111
|
+
string.each_char.select { |char| !(/[ -~。-゚]/.match(char)) }.count
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module NogizakaBlog
|
4
|
+
OptionParser.new do |opt|
|
5
|
+
opt.banner = "Usage: ruby nogizaka_blog.rb -m 201404"
|
6
|
+
|
7
|
+
opt.on('-m [yearmonth]', "specify the month you want to get. ex. 201404") do |yearmonth|
|
8
|
+
@yearmonth = yearmonth
|
9
|
+
unless ARGV.include?("-j")
|
10
|
+
nogizaka = NogizakaBlog::Amazing.new(@yearmonth)
|
11
|
+
nogizaka.__send__ :run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
opt.on('-j', 'JSON format') do
|
16
|
+
nogizaka = NogizakaBlog::Amazing.new(@yearmonth)
|
17
|
+
nogizaka.__send__ :gen_json
|
18
|
+
end
|
19
|
+
|
20
|
+
opt.on_tail('-v', '--version', 'Show version') do
|
21
|
+
puts "NogizakaBlog #{NogizakaBlog::VERSION}"
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
opt.parse!(ARGV)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,3 @@
|
|
1
|
+
module NogizakaBlog
|
2
|
+
MEMBER = {"manatsu.akimoto"=>"秋元真夏", "erika.ikuta"=>"生田絵梨花", "rina.ikoma"=>"生駒里奈", "rena.ichiki"=>"市來玲奈", "nene.ito"=>"伊藤寧々", "marika.ito"=>"伊藤万理華", "sayuri.inoue"=>"井上小百合", "misa.eto"=>"衛藤美彩", "hina.kawago"=>"川後陽菜", "mahiro.kawamura"=>"川村真洋", "hinako.kitano"=>"北野日奈子", "asuka.saito"=>"齋藤飛鳥", "chiharu.saito"=>"斎藤ちはる", "yuuri.saito"=>"斉藤優里", "reika.sakurai"=>"桜井玲香", "mai.shiraishi"=>"白石麻衣", "mai.shinuchi"=>"新内眞衣", "kazumi.takayama"=>"高山一実", "kana.nakada"=>"中田花奈", "himeka.nakamoto"=>"中元日芽香", "seira.nagashima"=>"永島聖羅", "nanase.nishino"=>"西野七瀬", "ami.noujo"=>"能條愛未", "nanami.hashimoto"=>"橋本奈々未", "seira.hatanaka"=>"畠中清羅", "hina.higuchi"=>"樋口日奈", "mai.fukagawa"=>"深川麻衣", "minami.hoshino"=>"星野みなみ", "miona.hori"=>"堀未央奈", "sayuri.matsumura"=>"松村沙友理", "rina.yamato"=>"大和里菜", "yumi.wakatsuki"=>"若月佑美", "maaya.wada"=>"和田まあや"}.freeze
|
3
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nogizaka_blog/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nogizaka_blog"
|
8
|
+
spec.version = NogizakaBlog::VERSION
|
9
|
+
spec.authors = ["hachy"]
|
10
|
+
spec.email = ["pekoett@gmail.com"]
|
11
|
+
spec.summary = %q{Get the number of comments and articles per month from Nogizaka46's blog}
|
12
|
+
spec.description = %q{Get the number of comments and articles per month from Nogizaka46's blog}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'nokogiri'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nogizaka_blog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hachy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Get the number of comments and articles per month from Nogizaka46's blog
|
56
|
+
email:
|
57
|
+
- pekoett@gmail.com
|
58
|
+
executables:
|
59
|
+
- nogizaka_blog
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/nogizaka_blog
|
69
|
+
- lib/nogizaka_blog.rb
|
70
|
+
- lib/nogizaka_blog/amazing.rb
|
71
|
+
- lib/nogizaka_blog/cli.rb
|
72
|
+
- lib/nogizaka_blog/core_ext.rb
|
73
|
+
- lib/nogizaka_blog/member.rb
|
74
|
+
- lib/nogizaka_blog/version.rb
|
75
|
+
- nogizaka_blog.gemspec
|
76
|
+
homepage: ''
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.2.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Get the number of comments and articles per month from Nogizaka46's blog
|
100
|
+
test_files: []
|