kansai_train_info 0.2.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/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/lib/kansai_train_info/cli.rb +17 -0
- data/lib/kansai_train_info/client.rb +84 -0
- data/lib/kansai_train_info/script.rb +23 -0
- data/lib/kansai_train_info/version.rb +5 -0
- data/lib/kansai_train_info.rb +7 -0
- metadata +120 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f2790271b1f1218907aa7674ac0331b31c4e69023cf7de17883f6a728e45f3ac
|
|
4
|
+
data.tar.gz: 2640173172839256d963e43845e37bfba2bd8584dbd763c1bce6b42759ec59c6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9825c11eec6dbe9199a731abd6fbd6e737e06bca1219071cbf0d3ed1e69bb3236b4f7b3b83efa70dc03ad4e8bdb04190335a8254bb649fce55789b0c6e9f05f5
|
|
7
|
+
data.tar.gz: 1cee51ebf59ea88fea66285bb8f67e982a1bbd9453432ed81d65a44e86e752d48eba45064d497893477b94ce7e4d2c5dd48bd00c98ad1b249c97931e22b025aa
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 okamotchan
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# kansai_train_info
|
|
2
|
+
|
|
3
|
+
obtain train operation status in the Kansai region of Japan
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
``` sh
|
|
8
|
+
irb(main):001:0> require 'kansai_train_info'
|
|
9
|
+
=> true
|
|
10
|
+
irb(main):002:0> KansaiTrainInfo.get(['大阪環状線'])
|
|
11
|
+
大阪環状線は平常運転です
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
now support: `大阪環状線, 近鉄京都線, 阪急京都線, 御堂筋線, 烏丸線, 東西線`
|
|
15
|
+
|
|
16
|
+
## requirements
|
|
17
|
+
|
|
18
|
+
Ruby >= 3.0.0
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
<details><summary>Trouble Shoot</summary>
|
|
22
|
+
|
|
23
|
+
### can't read gem
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
irb(main):001:0> require 'kansai_train_info'
|
|
27
|
+
Traceback (most recent call last):
|
|
28
|
+
6: from /Users/name/.rbenv/versions/2.7.1/bin/irb:23:in `<main>'
|
|
29
|
+
5: from /Users/name/.rbenv/versions/2.7.1/bin/irb:23:in `load'
|
|
30
|
+
4: from /Users/name/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/irb-1.2.3/exe/irb:11:in `<top (required)>'
|
|
31
|
+
3: from (irb):1
|
|
32
|
+
2: from /Users/name/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
|
|
33
|
+
1: from /Users/name/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
|
|
34
|
+
LoadError (cannot load such file -- KansaiTrainInfo)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
then excute
|
|
38
|
+
|
|
39
|
+
```txt
|
|
40
|
+
irb(main):002:0> $:
|
|
41
|
+
irb(main):003:0> $: << 'lib'
|
|
42
|
+
irb(main):012:0> require 'KansaiTrainInfo'
|
|
43
|
+
=> true
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
</details>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module KansaiTrainInfo
|
|
2
|
+
class CLI < Thor
|
|
3
|
+
desc "KansaiTrainInfo *routes", "Get"
|
|
4
|
+
def get(*routes)
|
|
5
|
+
texts = KansaiTrainInfo.get(routes)
|
|
6
|
+
texts.each do |text|
|
|
7
|
+
print text
|
|
8
|
+
print "\n"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
desc "KansaiTrainInfo help", "Help"
|
|
13
|
+
def help
|
|
14
|
+
KansaiTrainInfo.help
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# flozen_string_literal: true
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
|
|
5
|
+
module KansaiTrainInfo
|
|
6
|
+
class << self
|
|
7
|
+
LINES = {
|
|
8
|
+
大阪環状線: [4, 2, 263],
|
|
9
|
+
近鉄京都線: [6, 5, 288],
|
|
10
|
+
阪急京都線: [8, 2, 306],
|
|
11
|
+
御堂筋線: [10, 3, 321],
|
|
12
|
+
烏丸線: [34, 2, 318],
|
|
13
|
+
東西線: [34, 3, 319]
|
|
14
|
+
}.freeze
|
|
15
|
+
|
|
16
|
+
# rubocop:disable Metrics/AbcSize, Layout/LineLength
|
|
17
|
+
def get(route_array, url: false)
|
|
18
|
+
messages = []
|
|
19
|
+
|
|
20
|
+
route_array.each do |route|
|
|
21
|
+
line = LINES[route.to_sym]
|
|
22
|
+
raise KeyError, "Invalid route: #{route}" unless line
|
|
23
|
+
|
|
24
|
+
status_xpath = "//*[@id='mdAreaMajorLine']/div[#{LINES[route.to_sym][0]}]/table/tr[#{LINES[route.to_sym][1]}]/td[2]"
|
|
25
|
+
detail_url = "https://transit.yahoo.co.jp/traininfo/detail/#{LINES[route.to_sym][2]}/0/"
|
|
26
|
+
state = kansai_doc.xpath(status_xpath).first&.text
|
|
27
|
+
messages << message(route, state, url, detail_url)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
messages
|
|
31
|
+
end
|
|
32
|
+
# rubocop:enable Metrics/AbcSize, Layout/LineLength
|
|
33
|
+
|
|
34
|
+
def kansai_doc
|
|
35
|
+
charset = nil
|
|
36
|
+
url = 'https://transit.yahoo.co.jp/traininfo/area/6/'
|
|
37
|
+
|
|
38
|
+
html = URI.open(url) do |f|
|
|
39
|
+
charset = f.charset
|
|
40
|
+
f.read
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
Nokogiri::HTML.parse(html, nil, charset)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def description(detail_url)
|
|
47
|
+
charset = nil
|
|
48
|
+
detail_html = URI.open(detail_url) do |f|
|
|
49
|
+
charset = f.charset
|
|
50
|
+
f.read
|
|
51
|
+
end
|
|
52
|
+
detail_doc = Nokogiri::HTML.parse(detail_html, nil, charset)
|
|
53
|
+
detail_doc.xpath('//*[@id="mdServiceStatus"]/dl/dd/p').first.text
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
|
57
|
+
def message(route, state, url, detail_url)
|
|
58
|
+
return "#{route}は運行情報がありません" if state.nil?
|
|
59
|
+
|
|
60
|
+
state&.slice!('[○]')
|
|
61
|
+
state&.slice!('[!]')
|
|
62
|
+
puts "#{route}は#{state}です" if state == '平常運転'
|
|
63
|
+
message = case state
|
|
64
|
+
when '運転状況'
|
|
65
|
+
"#{route}は#{state}に変更があります。"
|
|
66
|
+
when '列車遅延'
|
|
67
|
+
"#{route}は#{state}があります。"
|
|
68
|
+
when '運転見合わせ'
|
|
69
|
+
"#{route}は#{state}しています。"
|
|
70
|
+
end
|
|
71
|
+
show_message = "#{message} #{description(detail_url)}"
|
|
72
|
+
url ? show_message + detail_url : show_message
|
|
73
|
+
end
|
|
74
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
|
75
|
+
|
|
76
|
+
def help
|
|
77
|
+
print '利用可能な路線:'
|
|
78
|
+
print "\n"
|
|
79
|
+
print "\n"
|
|
80
|
+
print '大阪環状線、近鉄京都線、阪急京都線, 御堂筋線, 烏丸線, 東西線'
|
|
81
|
+
print "\n"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
require 'open-uri'
|
|
5
|
+
|
|
6
|
+
url = 'https://transit.yahoo.co.jp/traininfo/area/6/'
|
|
7
|
+
|
|
8
|
+
charset = nil
|
|
9
|
+
|
|
10
|
+
html = open(url) do |f|
|
|
11
|
+
charset = f.charset
|
|
12
|
+
f.read
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
doc = Nokogiri::HTML.parse(html, nil, charset)
|
|
16
|
+
|
|
17
|
+
# doc.xpath('//div[@class="labelSmall"]').each do |node|
|
|
18
|
+
# p node.xpath('h3').text
|
|
19
|
+
# end
|
|
20
|
+
|
|
21
|
+
status_xpath = "//*[@id='mdAreaMajorLine']/div[4]/table/tr[3]/td[1]"
|
|
22
|
+
|
|
23
|
+
puts doc.xpath(status_xpath).first.text
|
metadata
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kansai_train_info
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- o8n
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-07-14 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: thor
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
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: bundler
|
|
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: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '12.3'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '12.3'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
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
|
+
description: you can check train info in kansai area
|
|
84
|
+
email:
|
|
85
|
+
- m.okamotchan@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- LICENSE.txt
|
|
91
|
+
- README.md
|
|
92
|
+
- lib/kansai_train_info.rb
|
|
93
|
+
- lib/kansai_train_info/cli.rb
|
|
94
|
+
- lib/kansai_train_info/client.rb
|
|
95
|
+
- lib/kansai_train_info/script.rb
|
|
96
|
+
- lib/kansai_train_info/version.rb
|
|
97
|
+
homepage:
|
|
98
|
+
licenses:
|
|
99
|
+
- MIT
|
|
100
|
+
metadata: {}
|
|
101
|
+
post_install_message:
|
|
102
|
+
rdoc_options: []
|
|
103
|
+
require_paths:
|
|
104
|
+
- lib
|
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: 2.3.0
|
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - ">="
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '0'
|
|
115
|
+
requirements: []
|
|
116
|
+
rubygems_version: 3.2.3
|
|
117
|
+
signing_key:
|
|
118
|
+
specification_version: 4
|
|
119
|
+
summary: check train info in kansai area
|
|
120
|
+
test_files: []
|