ffxiv_scraper 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/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/README.md +81 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ffxiv_scraper.gemspec +37 -0
- data/lib/ffxiv_scraper.rb +7 -0
- data/lib/ffxiv_scraper/lodestone/common.rb +38 -0
- data/lib/ffxiv_scraper/lodestone/news.rb +92 -0
- data/lib/ffxiv_scraper/lodestone/world_status.rb +61 -0
- data/lib/ffxiv_scraper/version.rb +3 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 18f46c70621308017159ec6c88775057f003a19e3a7bb9ed42038ea9050d1a26
|
4
|
+
data.tar.gz: d44da05b90122539a459f14f6517991b39d885ed3f178cd2e44fa0de937dee70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 236783c42468fcc794c4b9dfc1123f35d7e7abb7e47c46968d93fff36da55b65902fe77b541c788815748e58a4a1cd8636382d2199f3784e14e6695058278251
|
7
|
+
data.tar.gz: 9c204132f8e4b4faf2baf14f689aa77132940811cb6f9db43315615fed922849adc6ad7af3f8ddd9c388e5e00374c499e5212b5b9365c6f04324b165137ea36f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# FFXIVScraper
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ffxiv_scraper`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'ffxiv_scraper'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install ffxiv_scraper
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
ファイナルファンタジーXIVの公式サイト(Lodestone)をスクレイピングし、情報を取得するためのライブラリです。
|
25
|
+
|
26
|
+
#### ニュースの取得
|
27
|
+
指定したニュースを取得します。
|
28
|
+
|
29
|
+
* お知らせ
|
30
|
+
* メンテナンス
|
31
|
+
* アップデート
|
32
|
+
* 障害情報
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
news = FFXIVScraper::Lodestone::News.new(:notice)
|
36
|
+
news = FFXIVScraper::Lodestone::News.new(:maintenance)
|
37
|
+
news = FFXIVScraper::Lodestone::News.new(:update)
|
38
|
+
news = FFXIVScraper::Lodestone::News.new(:status)
|
39
|
+
list = news.news_list # get a news list
|
40
|
+
```
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
list.created_at # => ニュースの作成日時
|
44
|
+
list.title # => タイトル
|
45
|
+
list.detail_path # => 詳細ページのパス
|
46
|
+
list.tag # => タグ
|
47
|
+
|
48
|
+
detail = list.detail # => 詳細取得
|
49
|
+
detail.text # => ニュース本文
|
50
|
+
detail.next_path # => 次のページのパス
|
51
|
+
detail.prev_path # => 前のページのパス
|
52
|
+
detail.relationships # => 関連しているニュース
|
53
|
+
|
54
|
+
detail.detail_prev # => 前のページのニュースを取得
|
55
|
+
detail.detail_next # => 次のページのニュースを取得
|
56
|
+
```
|
57
|
+
|
58
|
+
#### ワールド稼働状況取得
|
59
|
+
ワールドの稼働状況を取得します。
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
world_status = FFXIVScraper::Lodestone::WorldStatus.new
|
63
|
+
|
64
|
+
status = world_status.get_status("ifrit") # => ワールドの稼働状況取得
|
65
|
+
status.dc # => データセンター名
|
66
|
+
status.world # => ワールド名
|
67
|
+
status.status # => 稼働状況
|
68
|
+
|
69
|
+
world_status.get_dc_statuses("gaia") # => DCのワールドの稼働状況取得
|
70
|
+
```
|
71
|
+
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
76
|
+
|
77
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ffxiv_scraper.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ffxiv_scraper"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "ffxiv_scraper/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ffxiv_scraper"
|
8
|
+
spec.version = FFXIVScraper::VERSION
|
9
|
+
spec.authors = ["Bal"]
|
10
|
+
spec.email = ["admin@vincanote.xyz"]
|
11
|
+
|
12
|
+
spec.summary = %q{FFXIV Scraper}
|
13
|
+
spec.description = %q{An unofficial Final Fantasy XIV scraper}
|
14
|
+
spec.homepage = "https://github.com/Vincanote/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_dependency "nokogiri"
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "ffxiv_scraper/version"
|
2
|
+
require 'open-uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module FFXIVScraper
|
6
|
+
module Lodestone
|
7
|
+
module Common
|
8
|
+
FFXIV_BASE_DOMAIN = "finalfantasyxiv.com".freeze
|
9
|
+
LODESTONE_PATH = "/lodestone".freeze
|
10
|
+
LANG = {ja: 'jp', na: 'na', eu:'eu', fr: 'fr', de: 'de'}.map(&:freeze).to_h.freeze
|
11
|
+
|
12
|
+
def set_locale(lang = :ja)
|
13
|
+
@lang = lang
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_base_url
|
17
|
+
return "https://#{LANG[@lang]}.#{FFXIV_BASE_DOMAIN}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_lodestone_url
|
21
|
+
return "https://#{LANG[@lang]}.#{FFXIV_BASE_DOMAIN}#{LODESTONE_PATH}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def open_html(url)
|
25
|
+
begin
|
26
|
+
charset = nil
|
27
|
+
html = open(url) do |f|
|
28
|
+
charset = f.charset
|
29
|
+
f.read
|
30
|
+
end
|
31
|
+
Nokogiri::HTML.parse(html, nil, charset)
|
32
|
+
rescue => exception
|
33
|
+
raise "url open exception. url [" << url << "]" << ", message [" << exception.message << "]"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "ffxiv_scraper/version"
|
2
|
+
require 'ffxiv_scraper/lodestone/common'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
module FFXIVScraper
|
7
|
+
module Lodestone
|
8
|
+
class News
|
9
|
+
include Common
|
10
|
+
CATEGORY = {notice: '1', maintenance: '2', update:'3', status: '4'}.map(&:freeze).to_h.freeze
|
11
|
+
|
12
|
+
def initialize(category = :notice)
|
13
|
+
@category = category
|
14
|
+
set_locale
|
15
|
+
unless CATEGORY.key?(category)
|
16
|
+
raise "not found category. [" + category.to_s + "]"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_news_url
|
21
|
+
return get_lodestone_url + "/news/category/#{CATEGORY[@category]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def news_list(backnumber = 0)
|
25
|
+
news_list = []
|
26
|
+
news_url = backnumber > 0 ? get_news_url << "?page=#{backnumber}" : get_news_url
|
27
|
+
|
28
|
+
doc = open_html(news_url)
|
29
|
+
doc.xpath('//li[@class="news__list"]').each do |news|
|
30
|
+
news_list << NewsContent.new(@lang, news.xpath('.//time').text[/strftime\((\d+),/,1].to_i,
|
31
|
+
news.xpath('.//p').text,
|
32
|
+
news.xpath('.//a/@href').text,
|
33
|
+
news.xpath('.//p/span').text)
|
34
|
+
end
|
35
|
+
news_list.sort { |a, b| b.created_at <=> a.created_at }
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
module Content
|
40
|
+
def get_detail(detail_path)
|
41
|
+
doc = open_html(get_base_url + detail_path)
|
42
|
+
|
43
|
+
detail = doc.xpath('//article')
|
44
|
+
relationships = []
|
45
|
+
detail.xpath('.//li[@class="news__list"]').each do |relation|
|
46
|
+
relationship = NewsContent.new(@lang, relation.xpath('.//time').text[/strftime\((\d+),/,1].to_i,
|
47
|
+
relation.xpath('.//p/span').text + relation.xpath('.//p/text()[2]').text.strip,
|
48
|
+
relation.xpath('./a/@href').text,
|
49
|
+
relation.xpath('.//p/span').text)
|
50
|
+
relationships << relationship
|
51
|
+
end
|
52
|
+
return DetailContent.new(@lang, detail.xpath('./div[@class="news__detail__wrapper"]').text,
|
53
|
+
detail.xpath('.//li[@class="news__nav__next"]/a/@href').text,
|
54
|
+
detail.xpath('.//li[@class="news__nav__prev"]/a/@href').text,
|
55
|
+
relationships)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
DetailContent = Struct.new("DetailContent", :text, :next_path, :prev_path, :relationships) do
|
60
|
+
include Common
|
61
|
+
include Content
|
62
|
+
|
63
|
+
def initialize(lang, text, next_path, prev_path, relationships)
|
64
|
+
set_locale(lang)
|
65
|
+
super(text, next_path, prev_path, relationships)
|
66
|
+
end
|
67
|
+
|
68
|
+
def detail_next
|
69
|
+
get_detail(next_path)
|
70
|
+
end
|
71
|
+
|
72
|
+
def detail_prev
|
73
|
+
get_detail(prev_path)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
NewsContent = Struct.new("NewsContent", :created_at, :title, :detail_path, :tag) do
|
78
|
+
include Common
|
79
|
+
include Content
|
80
|
+
|
81
|
+
def initialize(lang, created_at, title, detail_path, tag)
|
82
|
+
set_locale(lang)
|
83
|
+
super(created_at, title, detail_path, tag)
|
84
|
+
end
|
85
|
+
|
86
|
+
def detail
|
87
|
+
get_detail(detail_path)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "ffxiv_scraper/version"
|
2
|
+
require 'open-uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module FFXIVScraper
|
6
|
+
module Lodestone
|
7
|
+
class WorldStatus
|
8
|
+
include Common
|
9
|
+
INTERVAL = 10.freeze
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
set_locale
|
13
|
+
@needs_update = true
|
14
|
+
@update_at = Time.now
|
15
|
+
@statuses = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_locale(lang = :ja)
|
19
|
+
@lang = lang
|
20
|
+
@needs_update = true
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_statuses
|
24
|
+
if (Time.now - @update_at) > INTERVAL
|
25
|
+
@needs_update = true
|
26
|
+
end
|
27
|
+
|
28
|
+
if @needs_update
|
29
|
+
@statuses = []
|
30
|
+
doc = open_html(get_lodestone_url << "/worldstatus/")
|
31
|
+
dc_name = ""
|
32
|
+
doc.xpath('//h2[@class="heading--md parts__space--reset"]|//div[@class="item-list__worldstatus"]').each do |content|
|
33
|
+
world = ""
|
34
|
+
status = ""
|
35
|
+
if content.name == "h2"
|
36
|
+
dc_name = content.text.downcase
|
37
|
+
else
|
38
|
+
@statuses << Status.new(dc_name, content.xpath("./h3").text.downcase, content.xpath("./p").text.strip.downcase)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
@update_at = Time.now
|
42
|
+
@needs_update = false
|
43
|
+
end
|
44
|
+
return @statuses
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_status(world_name)
|
48
|
+
get_statuses
|
49
|
+
@statuses.find { |a| a.world == world_name.downcase }
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_dc_statuses(dc_name)
|
53
|
+
get_statuses
|
54
|
+
@statuses.select { |a| a.dc == dc_name.downcase }
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
Status = Struct.new("WorldStatus", :dc, :world, :status)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ffxiv_scraper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bal
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-07 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.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: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: An unofficial Final Fantasy XIV scraper
|
70
|
+
email:
|
71
|
+
- admin@vincanote.xyz
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- ffxiv_scraper.gemspec
|
85
|
+
- lib/ffxiv_scraper.rb
|
86
|
+
- lib/ffxiv_scraper/lodestone/common.rb
|
87
|
+
- lib/ffxiv_scraper/lodestone/news.rb
|
88
|
+
- lib/ffxiv_scraper/lodestone/world_status.rb
|
89
|
+
- lib/ffxiv_scraper/version.rb
|
90
|
+
homepage: https://github.com/Vincanote/
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata:
|
94
|
+
allowed_push_host: https://rubygems.org
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.7.6
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: FFXIV Scraper
|
115
|
+
test_files: []
|