nyaaaaa 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e411c99a496417889d2b43525c4c5db907e572b
4
+ data.tar.gz: 39fb7081a486f82e9f06784f3d737a3ca2733572
5
+ SHA512:
6
+ metadata.gz: 0a2fb00e4f06559ce82df6c0657483088a000faf7e012a922205233a62d629cf652a831149e2e081271f6de13dde55bb558c842e7d1b850445ff2c192535e19a
7
+ data.tar.gz: fde2dd9a956abe3514e33b41b9d04b3207656d14c3d3a3cdc54f4080126f882c0b780e6213b06e50f0e23a341bea6dd541bf866bb7c80da1fe9269263925b645
@@ -0,0 +1,18 @@
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
+ var
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nyaaaaa.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 yukihiro hara
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.
@@ -0,0 +1,25 @@
1
+ # Nyaaaaa
2
+
3
+ Cats fix everything in your life.
4
+
5
+ ## Installation
6
+
7
+ $ gem install nyaaaaa
8
+
9
+ ## Usage
10
+
11
+ $ nyaaaaa
12
+
13
+ And you will be satisfied.
14
+
15
+ To update image info:
16
+
17
+ $ nyaaaaa update
18
+
19
+ ## Contributing
20
+
21
+ 1. Fork it
22
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
23
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
24
+ 4. Push to the branch (`git push origin my-new-feature`)
25
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nyaaaaa/cli'
3
+ Nyaaaaa::CLI.start
@@ -0,0 +1,93 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "nyaaaaa/version"
3
+ require 'addressable/uri'
4
+ require 'open-uri'
5
+ require 'nokogiri'
6
+
7
+ module Nyaaaaa
8
+ BASE_URL = "http://ねこ画像.net/"
9
+ PAGE_PATH_TMPL = "neko%05d"
10
+ XPATH_LATEST_LINK = '//*[@id="content"]/div[1]/a'
11
+ GEM_ROOT = Gem::Specification.find_by_name('nyaaaaa').gem_dir
12
+
13
+ class RequestError < StandardError
14
+ end
15
+ class ParseError < StandardError
16
+ end
17
+
18
+ module ModuleMethods
19
+ def get_index_html
20
+ begin
21
+ url = Addressable::URI.parse(BASE_URL)
22
+
23
+ charset = nil
24
+ html = open(url.normalize.to_s) do |f|
25
+ charset = f.charset
26
+ f.read
27
+ end
28
+ [html, charset]
29
+ rescue
30
+ raise RequestError, "Request to #{BASE_URL} has failed."
31
+ end
32
+ end
33
+
34
+ def scrape_latest_id(html, charset)
35
+ begin
36
+ doc = Nokogiri::HTML.parse(html, nil , charset)
37
+ href = nil
38
+ doc.xpath(XPATH_LATEST_LINK).each do |node|
39
+ href = node.attribute('href').value
40
+ end
41
+ href.match(/\/neko(\d+)\//)[1].to_i
42
+ rescue
43
+ raise ParseError, "Parsing response HTML has failed."
44
+ end
45
+ end
46
+
47
+ def get_latest_id
48
+ scrape_latest_id(*get_index_html)
49
+ end
50
+
51
+ def var_dir
52
+ File.join GEM_ROOT, 'var'
53
+ end
54
+
55
+ def latest_id_cache_path
56
+ File.join var_dir, 'latest_id'
57
+ end
58
+
59
+ def save_latest_id(id)
60
+ unless File.exists? var_dir
61
+ FileUtils.mkdir var_dir
62
+ end
63
+ IO.write(latest_id_cache_path, id.to_s)
64
+ end
65
+
66
+ def fetch_latest_id
67
+ id = get_latest_id
68
+ save_latest_id(id)
69
+ id
70
+ end
71
+
72
+ def latest_id
73
+ unless File.exists? latest_id_cache_path
74
+ fetch_latest_id
75
+ end
76
+ IO.read(latest_id_cache_path).to_i
77
+ end
78
+
79
+ def url_with_id(id)
80
+ BASE_URL + sprintf(PAGE_PATH_TMPL, id) + '/'
81
+ end
82
+
83
+ def latest_url
84
+ url_with_id latest_id
85
+ end
86
+
87
+ def random_url
88
+ url_with_id Random.rand(1..latest_id)
89
+ end
90
+ end
91
+
92
+ extend ModuleMethods
93
+ end
@@ -0,0 +1,18 @@
1
+ require 'nyaaaaa'
2
+ require 'launchy'
3
+ require 'thor'
4
+
5
+ module Nyaaaaa
6
+ class CLI < Thor
7
+ desc 'update', 'update to latest image data'
8
+ def update
9
+ puts 'Update latest id to: ' + Nyaaaaa.fetch_latest_id.to_s
10
+ end
11
+
12
+ desc 'nyaaaaa', 'Nyaaaaaaaaaaaaaaaaaaaaaaaaaaaa!'
13
+ def nyaaaaa
14
+ Launchy.open Nyaaaaa.random_url
15
+ end
16
+ default_task :nyaaaaa
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Nyaaaaa
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nyaaaaa/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nyaaaaa"
8
+ spec.version = Nyaaaaa::VERSION
9
+ spec.authors = ["yukihiro hara"]
10
+ spec.email = ["yukihr@gmail.com"]
11
+ spec.description = %q{Cats fix everything in your life.}
12
+ spec.summary = %q{Cat is your saviour.}
13
+ spec.homepage = "http://yukihr.github.io"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "nokogiri"
25
+ spec.add_development_dependency "addressable"
26
+ spec.add_development_dependency "launchy"
27
+ spec.add_development_dependency "thor"
28
+ end
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'nyaaaaa'
3
+
4
+ describe Nyaaaaa do
5
+ describe 'get_latest_id' do
6
+ original_base_url = Nyaaaaa::BASE_URL
7
+ after do
8
+ Nyaaaaa::BASE_URL = original_base_url
9
+ end
10
+ it 'should get get_latest_id' do
11
+ Nyaaaaa.get_latest_id.should be_an_instance_of(Fixnum)
12
+ end
13
+ it 'should raise RequestError for non-exist url' do
14
+ lambda{
15
+ Nyaaaaa::BASE_URL = 'http://nyaaaaatest.net'
16
+ Nyaaaaa.get_latest_id
17
+ }.should raise_error(Nyaaaaa::RequestError)
18
+ end
19
+ it 'should raise ParseError for wrong html' do
20
+ lambda{
21
+ Nyaaaaa::BASE_URL = 'http://example.com'
22
+ Nyaaaaa.get_latest_id
23
+ }.should raise_error(Nyaaaaa::ParseError)
24
+ end
25
+ end
26
+
27
+ describe 'save_latest_id' do
28
+ it 'should write latest_id' do
29
+ Nyaaaaa.save_latest_id(2048)
30
+ IO.read(Nyaaaaa.latest_id_cache_path).should eq('2048')
31
+ end
32
+ end
33
+
34
+ describe 'latest_id' do
35
+ it 'should return latest id' do
36
+ Nyaaaaa.latest_id.should be_an_instance_of(Fixnum)
37
+ end
38
+ end
39
+
40
+ describe 'url_with_id' do
41
+ it 'should return url with id' do
42
+ Nyaaaaa.url_with_id(123).should eq('http://ねこ画像.net/neko00123/')
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nyaaaaa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - yukihiro hara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
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
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: launchy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Cats fix everything in your life.
112
+ email:
113
+ - yukihr@gmail.com
114
+ executables:
115
+ - nyaaa
116
+ - nyaaaa
117
+ - nyaaaaa
118
+ - nyaaaaaa
119
+ - nyaaaaaaa
120
+ - nyaaaaaaaa
121
+ - nyaaaaaaaaa
122
+ - nyaaaaaaaaaa
123
+ - nyaaaaaaaaaaa
124
+ - nyaaaaaaaaaaaa
125
+ - nyaaaaaaaaaaaaa
126
+ - nyaaaaaaaaaaaaaa
127
+ - nyaaaaaaaaaaaaaaa
128
+ - nyaaaaaaaaaaaaaaaa
129
+ - nyaaaaaaaaaaaaaaaaa
130
+ - nyaaaaaaaaaaaaaaaaaa
131
+ - nyaaaaaaaaaaaaaaaaaaa
132
+ - nyaaaaaaaaaaaaaaaaaaaa
133
+ - nyaaaaaaaaaaaaaaaaaaaaa
134
+ - nyaaaaaaaaaaaaaaaaaaaaaa
135
+ - nyaaaaaaaaaaaaaaaaaaaaaaa
136
+ - nyaaaaaaaaaaaaaaaaaaaaaaaa
137
+ - nyaaaaaaaaaaaaaaaaaaaaaaaaa
138
+ extensions: []
139
+ extra_rdoc_files: []
140
+ files:
141
+ - .gitignore
142
+ - Gemfile
143
+ - LICENSE.txt
144
+ - README.md
145
+ - Rakefile
146
+ - bin/nyaaa
147
+ - bin/nyaaaa
148
+ - bin/nyaaaaa
149
+ - bin/nyaaaaaa
150
+ - bin/nyaaaaaaa
151
+ - bin/nyaaaaaaaa
152
+ - bin/nyaaaaaaaaa
153
+ - bin/nyaaaaaaaaaa
154
+ - bin/nyaaaaaaaaaaa
155
+ - bin/nyaaaaaaaaaaaa
156
+ - bin/nyaaaaaaaaaaaaa
157
+ - bin/nyaaaaaaaaaaaaaa
158
+ - bin/nyaaaaaaaaaaaaaaa
159
+ - bin/nyaaaaaaaaaaaaaaaa
160
+ - bin/nyaaaaaaaaaaaaaaaaa
161
+ - bin/nyaaaaaaaaaaaaaaaaaa
162
+ - bin/nyaaaaaaaaaaaaaaaaaaa
163
+ - bin/nyaaaaaaaaaaaaaaaaaaaa
164
+ - bin/nyaaaaaaaaaaaaaaaaaaaaa
165
+ - bin/nyaaaaaaaaaaaaaaaaaaaaaa
166
+ - bin/nyaaaaaaaaaaaaaaaaaaaaaaa
167
+ - bin/nyaaaaaaaaaaaaaaaaaaaaaaaa
168
+ - bin/nyaaaaaaaaaaaaaaaaaaaaaaaaa
169
+ - lib/nyaaaaa.rb
170
+ - lib/nyaaaaa/cli.rb
171
+ - lib/nyaaaaa/version.rb
172
+ - nyaaaaa.gemspec
173
+ - spec/nyaaaaa_spec.rb
174
+ homepage: http://yukihr.github.io
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.0.3
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Cat is your saviour.
198
+ test_files:
199
+ - spec/nyaaaaa_spec.rb