erogamescape 0.1.0
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE +21 -0
- data/README.md +41 -0
- data/lib/erogamescape/errors.rb +11 -0
- data/lib/erogamescape/version.rb +5 -0
- data/lib/erogamescape.rb +45 -0
- data/sig/erogamescape.rbs +13 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd2e6d649d39dfa279acd14a5bc698845930f47cd7f02dd6510ed4e58abd19ff
|
4
|
+
data.tar.gz: 2b3cf73fe7e415e59a2c8d0ed99e29d0e56c4b7e932126e88c9dbee340ae5f72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 227dc94a2a9496b2790e26af8c36a649de195c22e171fda6233194a4f96cc1f0765ff0f57e39d2f50a745f677bf4c731a3041bfde493774c9a08069c94030ab1
|
7
|
+
data.tar.gz: 5533c6adbeb0f7fd2513770e40ee07f5be6ed960aabed309e798d9e47d32396d52a370ad1438eba21dea3553561629fdb40c54cd5c71b497187cc86aade1487f
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 fabon
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Erogamescape
|
2
|
+
|
3
|
+
ErogameScape (エロゲー批評空間) scraper
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ bundle add erogamescape
|
8
|
+
|
9
|
+
Or install globally:
|
10
|
+
|
11
|
+
$ gem install erogamescape
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
result = Erogamescape.query(<<SQL)
|
17
|
+
SELECT id, brandname, median
|
18
|
+
FROM brandlist
|
19
|
+
WHERE id = 1
|
20
|
+
SQL
|
21
|
+
|
22
|
+
result.size # 1
|
23
|
+
result.first # { "id" => "1", "brandname" => "âge(age)", "median" => "81" }
|
24
|
+
```
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
Run `bin/setup` to set up the project.
|
29
|
+
|
30
|
+
Some useful commands are available:
|
31
|
+
|
32
|
+
* `bundle exec rake test`: run the tests
|
33
|
+
* `bin/console`: an interactive prompt that will allow you to experiment
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/fabon-f/erogamescape.rb>.
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
[MIT License](https://opensource.org/licenses/MIT)
|
data/lib/erogamescape.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "net/http"
|
5
|
+
require "oga"
|
6
|
+
|
7
|
+
require_relative "erogamescape/version"
|
8
|
+
require_relative "erogamescape/errors"
|
9
|
+
|
10
|
+
module Erogamescape
|
11
|
+
def self.parse_response_html(html)
|
12
|
+
doc = Oga.parse_html(html)
|
13
|
+
title = doc.at_css("#query_result_header h3")&.text
|
14
|
+
if doc.at_css("#queryplan_main").nil?
|
15
|
+
text = doc.at_css("#query_result_main")&.text
|
16
|
+
raise WrongSqlError.new(text) if title == "エラー(SQL間違い)"
|
17
|
+
raise SqlError.new(text)
|
18
|
+
end
|
19
|
+
|
20
|
+
if doc.at_css("#query_result_main table").nil?
|
21
|
+
text = doc.at_css("#query_result_main")&.text
|
22
|
+
raise RuntimeSqlError.new(text)
|
23
|
+
end
|
24
|
+
|
25
|
+
columns = doc.css("#query_result_main th").map(&:text)
|
26
|
+
doc.css("#query_result_main tr").map do |row|
|
27
|
+
row_data = row.css("td").map(&:text)
|
28
|
+
row_data.size == 0 ? nil : columns.zip(row_data).to_h
|
29
|
+
end.compact
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.post_sql(sql)
|
33
|
+
uri = URI.parse("https://erogamescape.dyndns.org/~ap2/ero/toukei_kaiseki/sql_for_erogamer_form.php")
|
34
|
+
body = URI.encode_www_form({ "sql" => sql })
|
35
|
+
response = Net::HTTP.post(uri, body, { "Content-Type" => "application/x-www-form-urlencoded" })
|
36
|
+
response.value
|
37
|
+
response.body.force_encoding("UTF-8")
|
38
|
+
end
|
39
|
+
|
40
|
+
private_class_method :parse_response_html, :post_sql
|
41
|
+
|
42
|
+
def self.query(sql)
|
43
|
+
self.parse_response_html(self.post_sql(sql))
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Erogamescape
|
2
|
+
VERSION: String
|
3
|
+
class SqlError < StandardError
|
4
|
+
end
|
5
|
+
class WrongSqlError < StandardError
|
6
|
+
end
|
7
|
+
class RuntimeSqlError < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
private def self.parse_response_html: (String html) -> Array[Hash[String, String]]
|
11
|
+
private def self.post_sql: (String sql) -> String
|
12
|
+
def self.query: (String sql) -> Array[Hash[String, String]]
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: erogamescape
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- fabon
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oga
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.4'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- syobon.hinata.public@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- lib/erogamescape.rb
|
38
|
+
- lib/erogamescape/errors.rb
|
39
|
+
- lib/erogamescape/version.rb
|
40
|
+
- sig/erogamescape.rbs
|
41
|
+
homepage: https://github.com/fabon-f/erogamescape.rb
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata:
|
45
|
+
homepage_uri: https://github.com/fabon-f/erogamescape.rb
|
46
|
+
source_code_uri: https://github.com/fabon-f/erogamescape.rb
|
47
|
+
changelog_uri: https://github.com/fabon-f/erogamescape.rb/blob/master/CHANGELOG.md
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 3.0.6
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubygems_version: 3.5.3
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: ErogameScape scraper
|
67
|
+
test_files: []
|