rakuten_securities_scraper 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bda3af5dc3b21c8c6ec54d33c5893400f7164df75a7eeaf6ab768ce314e0ade
4
- data.tar.gz: 2c21e09bc510161f97ee42fb144545cafa9d630f647cdfb945c057049cf9851d
3
+ metadata.gz: af1bd8cc0abba9b3116e6636a63ca1c2e8444cef3dcd235302bdf42eb7dd6836
4
+ data.tar.gz: a9a10da8d97ce4988b601bc9fcf75329e6782a865636478f679fe0751d582060
5
5
  SHA512:
6
- metadata.gz: be780e7e99a503791fb907e0d006b2923c6958827a12e6e33abbff08d79199a2ba7c01865c02f4c1a3620a8af155989b2df8e54488c60d666410e9d96a18f817
7
- data.tar.gz: 95d8916aea0f264a536fefbc5349c83d7f34fb9d5bb114907ca4eed3557a829367204b14f5cb08573b0637ee62b41ee45dfc272420ff1b9e110d7f96d46e1f3d
6
+ metadata.gz: 74b63aebc080956c50f098e7bf699ceb19f8b0699b701f1e20aeaafd3361ef7c0ef266ae6fd5442944980ffa83fd007400c9383af2c61e9dea27b0fd964f1c75
7
+ data.tar.gz: '0961d672f7f487d62464a3a2a4ce16adb04bcd6ddc7f7e53b640b24a7dcefbb49795196db45f814e7593c14e9ef2a5caf144430e8b422c44f58b779e2f449813'
@@ -171,9 +171,8 @@ Lint/UnusedMethodArgument:
171
171
  Metrics/AbcSize:
172
172
  Enabled: false
173
173
 
174
- # 6 は強すぎるので緩める
175
174
  Metrics/CyclomaticComplexity:
176
- Max: 10
175
+ Enabled: false
177
176
 
178
177
  Metrics/PerceivedComplexity:
179
178
  Enabled: false
@@ -222,4 +221,6 @@ Style/ConstantVisibility:
222
221
  Style/MutableConstant:
223
222
  Enabled: false
224
223
  Style/Copyright:
224
+ Enabled: false
225
+ Layout/MultilineAssignmentLayout:
225
226
  Enabled: false
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rakuten_securities_scraper (0.1.0)
4
+ rakuten_securities_scraper (0.1.5)
5
+ selenium-webdriver (~> 3.142.7)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -50,6 +51,7 @@ PLATFORMS
50
51
  ruby
51
52
 
52
53
  DEPENDENCIES
54
+ bundler (~> 2.0)
53
55
  rake (~> 12.0)
54
56
  rakuten_securities_scraper!
55
57
  rspec (~> 3.0)
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 ELSOUL
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 CHANGED
@@ -1,8 +1,36 @@
1
+ [![RakutenSecuritiesScraper](https://firebasestorage.googleapis.com/v0/b/el-quest.appspot.com/o/mediaLibrary%2F1589293505170_rakuten-shoken.jpg?alt=media&token=f86b6870-fd3f-42aa-805d-db35cb53a9b6)](https://www.rakuten-sec.co.jp/)
2
+
3
+ <p align="center">
4
+
5
+ <a aria-label="Ruby logo" href="https://el-soul.com">
6
+ <img src="https://badgen.net/badge/icon/Made%20by%20ELSOUL?icon=ruby&label&color=black&labelColor=black">
7
+ </a>
8
+ <br/>
9
+
10
+ <a aria-label="Ruby Gem version" href="https://rubygems.org/gems/rakuten_securities_scraper">
11
+ <img alt="" src="https://badgen.net/rubygems/v/rakuten_securities_scraper/latest">
12
+ </a>
13
+ <a aria-label="Downloads Number" href="https://rubygems.org/gems/rakuten_securities_scraper">
14
+ <img alt="" src="https://badgen.net/rubygems/dt/rakuten_securities_scraper">
15
+ </a>
16
+ <a aria-label="License" href="https://github.com/elsoul/rakuten_securities_scraper/blob/master/LICENSE">
17
+ <img alt="" src="https://badgen.net/badge/license/MIT/blue">
18
+ </a>
19
+ </p>
20
+
1
21
  # RakutenSecuritiesScraper
2
22
 
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/rakuten_securities_scraper`. To experiment with that code, run `bin/console` for an interactive prompt.
23
+ Rakuten Securities Scraper / 楽天証券スクレイパー
24
+
25
+ ## Introduction
26
+
27
+ This gem is providing scraper methods for everyone to be able to make stock trading applications without writing scraper codes.
4
28
 
5
- TODO: Delete this and the text above, and describe your gem
29
+ It features:
30
+
31
+ - Get all trading histories
32
+ - Auto Buying (future)
33
+ - Auto Selling (future)
6
34
 
7
35
  ## Installation
8
36
 
@@ -22,16 +50,23 @@ Or install it yourself as:
22
50
 
23
51
  ## Usage
24
52
 
25
- ruby```
53
+ ```ruby
26
54
  include RakutenSecuritiesScraper
27
55
  data = RakutenScraper.new($LOGIN_ID, $LOGIN_PW)
28
56
 
29
-
30
57
  ## Get Today's Trade History
31
- data.todays_history
58
+ puts data.todays_history
32
59
 
33
60
  ## Get All Trade History
34
- data.all_history
61
+ puts data.all_history
62
+
63
+ ## Get Today's Executed Order
64
+ puts data.todays_order
65
+
66
+ ## Add favorite list
67
+ page_num : Integer 1..10
68
+ codes : Array ["4755", "4875",,,]
69
+ puts data.favorite page_num, codes
35
70
 
36
71
  ```
37
72
 
@@ -39,9 +74,8 @@ ruby```
39
74
 
40
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.
41
76
 
42
- 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).
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/gems/rakuten_securities_scraper).
43
78
 
44
79
  ## Contributing
45
80
 
46
81
  Bug reports and pull requests are welcome on GitHub at https://github.com/elsoul/rakuten_securities_scraper.
47
-
@@ -11,6 +11,157 @@ module RakutenSecuritiesScraper
11
11
  }
12
12
  end
13
13
 
14
+ def login
15
+ driver = get_selenium_driver(:chrome)
16
+ url = "https://www.rakuten-sec.co.jp/ITS/V_ACT_Login.html"
17
+ driver.get url
18
+ driver.find_element(id: "form-login-id").send_keys @login[:login_id]
19
+ driver.find_element(id: "form-login-pass").send_keys @login[:login_pw]
20
+ driver.find_element(id: "login-btn").click
21
+ driver
22
+ end
23
+
24
+ def favorite num, codes
25
+ driver = login
26
+ sleep 2
27
+ driver.action.move_to(driver.find_element(id: "gmenu_domestic_stock")).perform
28
+ sleep 2
29
+ driver.find_element(id: "gmenu_domestic_stock").click
30
+ sleep 2
31
+ driver.find_element(link_text: "お気に入り銘柄").click
32
+ sleep 2
33
+ driver.find_element(link_text: num).click
34
+ sleep 2
35
+ driver.find_element(name: "editAnchor").click
36
+ sleep 2
37
+ driver.find_element(name: "addAnchor").click
38
+ sleep 1
39
+ driver.switch_to.frame driver.find_element(:id, "TB_iframeContent")
40
+ codes.each do |code|
41
+ result = click_favorite driver, code
42
+ next if result == "already exist"
43
+ end
44
+ driver.find_element(id: "prc_save_button1").click
45
+ { status: "success" }
46
+ end
47
+
48
+ def delete_favorite page_num
49
+ driver = login
50
+ sleep 2
51
+ driver.action.move_to(driver.find_element(id: "gmenu_domestic_stock")).perform
52
+ sleep 2
53
+ driver.find_element(id: "gmenu_domestic_stock").click
54
+ sleep 2
55
+ driver.find_element(link_text: "お気に入り銘柄").click
56
+ sleep 2
57
+ driver.find_element(link_text: page_num).click
58
+ sleep 2
59
+ driver.find_element(name: "editAnchor").click
60
+ sleep 2
61
+ table = driver.find_element(class_name: "tbl-data-01")
62
+ rows = table.find_elements(xpath: "//tr")
63
+ last_row = rows.size - 2
64
+ rows[2..last_row].each do |row|
65
+ driver.find_element(id: "line_delete_button_1").click
66
+ driver.switch_to.alert.accept
67
+ sleep 1
68
+ end
69
+ driver.find_element(id: "prc_save_button1").click
70
+ { status: "success" }
71
+ end
72
+
73
+ def click_favorite driver, code
74
+ sleep 2
75
+ driver.find_element(name: "dscrCdNm").clear
76
+ driver.find_element(name: "dscrCdNm").send_keys code
77
+ driver.find_element(name: "dscrCdNm").send_keys(:enter)
78
+ sleep 2
79
+ rows = driver.find_elements(xpath: "//tr")
80
+ value = ""
81
+ num = 0
82
+ rows[3..rows.size - 1].each_with_index do |f, i|
83
+ cells = f.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
84
+ value = i if cells[1] == code and cells[3] == "東証"
85
+ num += 1
86
+ end
87
+ while value == ""
88
+ driver.find_element(xpath: "//*[@id='str-main-inner']/table/tbody/tr/td/table/tbody/tr/td/form/ul/li[2]/a").click
89
+ rows = driver.find_elements(xpath: "//tr")
90
+ rows[3..rows.size - 1].each_with_index do |f, i|
91
+ cells = f.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
92
+ value = i + num - 1 if cells[1] == code and cells[3] == "東証"
93
+ end
94
+ end
95
+ driver.find_element(xpath: "//*[@id='#{value}']").click
96
+ sleep 2
97
+ driver.find_element(xpath: "//*[@id='str-main-inner']/table/tbody/tr/td/table/tbody/tr/td/form/div[3]/ul/li/a/img").click
98
+ begin
99
+ return "already exist" if driver.find_element(xpath: "//*[@id='err_msg']").text.include? "すでに登録済みの銘柄が含まれています。"
100
+ rescue
101
+ end
102
+ driver
103
+ end
104
+
105
+ def todays_order
106
+ driver = get_selenium_driver(:chrome)
107
+ wait = Selenium::WebDriver::Wait.new(timeout: 100)
108
+ url = "https://www.rakuten-sec.co.jp/ITS/V_ACT_Login.html"
109
+ driver.get url
110
+ driver.find_element(id: "form-login-id").send_keys @login[:login_id]
111
+ driver.find_element(id: "form-login-pass").send_keys @login[:login_pw]
112
+ driver.find_element(id: "login-btn").click
113
+ sleep 2
114
+ driver.action.move_to(driver.find_element(id: "gmenu_domestic_stock")).perform
115
+ sleep 2
116
+ driver.find_element(id: "gmenu_domestic_stock").click
117
+ sleep 2
118
+ driver.find_element(id: "nav-sub-menu-order-arrow").click
119
+ wait.until { driver.find_element(xpath: "//*[@id='str-main-inner']/table/tbody/tr/td/form/div[2]/div/ul/li[3]/a") }
120
+ driver.find_element(xpath: "//*[@id='str-main-inner']/table/tbody/tr/td/form/div[2]/div/ul/li[3]/a").click
121
+ sleep 2
122
+ span_select = Selenium::WebDriver::Support::Select.new(driver.find_element(:id, "orderStatus"))
123
+ span_select.select_by(:value, "5")
124
+ sleep 1
125
+ driver.find_element(css: "input[type='image']").click
126
+ sleep 2
127
+ tables = driver.find_elements(xpath: "//tr")
128
+ page_num = driver.find_element(class_name: "mtext").text.scan(/(.+)件中/)[0][0].to_i
129
+ row_nums = (21..(21 + (page_num * 3) - 1)).to_a
130
+ records = []
131
+ row_nums.each_slice(3).to_a.map do |col_num|
132
+ detail = {}
133
+ tables[col_num[0]..col_num[2]].map.with_index do |row, i|
134
+ cells = row.find_elements(:css, "td").map(&:text)
135
+ case i
136
+ when 0
137
+ detail[:order_id] = cells[0] if cells[0]
138
+ detail[:order_status] = cells[1] if cells[1]
139
+ detail[:order_date] = cells[2] if cells[2]
140
+ detail[:stock_name] = cells[3].split("\n")[0] if cells[3]
141
+ detail[:code] = cells[3].split("\n")[1].split(" ")[0] if cells[3]
142
+ detail[:market] = cells[3].split("\n")[1].split(" ")[1] if cells[3]
143
+ detail[:trade_type] = cells[4] if cells[4]
144
+ detail[:buy_sell] = cells[5] if cells[5]
145
+ detail[:order_amount] = cells[7] if cells[7]
146
+ detail[:unit_price] = cells[8] if cells[8]
147
+ detail[:executed_price] = cells[8] if cells[8]
148
+ when 1
149
+ detail[:order_condition] = cells[2] if cells[2]
150
+ detail[:account_type] = cells[3] if cells[3]
151
+ detail[:executed_price] = cells[5] if cells[5]
152
+ detail[:fee] = cells[6] if cells[6]
153
+ else
154
+ detail[:order_expire_date] = cells[2] if cells[2]
155
+ detail[:order_type] = cells[3] if cells[3]
156
+ end
157
+ records << detail
158
+ end
159
+ end
160
+ records
161
+ ensure
162
+ driver.quit
163
+ end
164
+
14
165
  def all_history
15
166
  driver = get_selenium_driver(:chrome)
16
167
  wait = Selenium::WebDriver::Wait.new(timeout: 100)
@@ -47,9 +198,11 @@ module RakutenSecuritiesScraper
47
198
  driver.find_element(id: "login-btn").click
48
199
  wait.until { driver.find_element(id: "header-menu-button-asset") }
49
200
  driver.action.move_to(driver.find_element(id: "header-menu-button-asset")).perform
201
+ sleep 2
50
202
  wait.until { driver.find_element(xpath: "/html/body/div[2]/div/div/div[2]/ul[1]/li[1]/ul/li[1]/a") }
203
+ sleep 2
51
204
  driver.find_element(xpath: "/html/body/div[2]/div/div/div[2]/ul[1]/li[1]/ul/li[1]/a").click
52
-
205
+ sleep 3
53
206
  driver.find_element(css: "input[type='image']").click
54
207
  sleep 2
55
208
  rows = driver.find_elements(xpath: "//tr")
@@ -66,7 +219,7 @@ module RakutenSecuritiesScraper
66
219
  def trade_table_data driver, page_num
67
220
  run_times = page_num.divmod(20)
68
221
  trade_records = []
69
- (1..run_times[0]-1).each do |f|
222
+ (1..run_times[0] - 1).each do |f|
70
223
  rows = driver.find_elements(xpath: "//tr")
71
224
  rows[10..29].map do |row|
72
225
  cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
@@ -89,14 +242,19 @@ module RakutenSecuritiesScraper
89
242
  tax_type: cells[7].split("\n")[1],
90
243
  total_price: cells[8]
91
244
  }
92
- return trade_records if page_num < 20
93
245
  end
246
+ puts trade_records
247
+ return trade_records if page_num < 20
94
248
  driver.find_element(link: "次の20件").click
95
249
  end
96
250
  sleep 2
97
- driver.find_element(link: "次の#{run_times[1]}件").click
251
+ begin
252
+ driver.find_element(link: "次の#{run_times[1]}件").click
253
+ rescue
254
+ return trade_records
255
+ end
98
256
  rows = driver.find_elements(xpath: "//tr")
99
- rows[10.."1#{run_times[1]}".to_i-1].map do |row|
257
+ rows[10.."1#{run_times[1]}".to_i - 1].map do |row|
100
258
  cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
101
259
  trade_records << {
102
260
  bit_date: cells[0].split("\n")[0],
@@ -134,7 +292,7 @@ module RakutenSecuritiesScraper
134
292
  options.add_argument("--disable-popup-blocking")
135
293
  options.add_argument("--disable-translate")
136
294
  options.add_argument("-headless")
137
- Selenium::WebDriver.for :chrome, options: options
295
+ Selenium::WebDriver.for :chrome # , options: options
138
296
  end
139
297
  end
140
298
  end
@@ -1,3 +1,3 @@
1
1
  module RakutenSecuritiesScraper
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.email = ["fumitake.kawasaki@el-soul.com"]
8
8
 
9
9
  spec.summary = "楽天証券スクレイパー / Rakuten Securities Scraper"
10
- spec.description = "楽天証券スクレイパー / Rakuten Securities Scraper"
10
+ spec.description = "This gem is providing scraper methods for everyone to be able to make stock trading applications without writing scraper codes."
11
11
  spec.homepage = "https://github.com/elsoul/rakuten_securities"
12
12
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
13
13
  spec.license = "MIT"
@@ -23,4 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.bindir = "exe"
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", ">= 12.3.3"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_runtime_dependency "selenium-webdriver", "~> 3.142.7"
26
30
  end
metadata CHANGED
@@ -1,16 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rakuten_securities_scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - FUMI-POPPIN
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-10 00:00:00.000000000 Z
12
- dependencies: []
13
- description: 楽天証券スクレイパー / Rakuten Securities Scraper
11
+ date: 2020-06-09 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
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: selenium-webdriver
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.142.7
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.142.7
69
+ description: This gem is providing scraper methods for everyone to be able to make
70
+ stock trading applications without writing scraper codes.
14
71
  email:
15
72
  - fumitake.kawasaki@el-soul.com
16
73
  executables: []
@@ -23,6 +80,7 @@ files:
23
80
  - ".travis.yml"
24
81
  - Gemfile
25
82
  - Gemfile.lock
83
+ - LICENSE
26
84
  - README.md
27
85
  - Rakefile
28
86
  - bin/console