rakuten_securities_scraper 0.1.2 → 0.1.7

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: 58abe4bab9e94f8c492e3f38a056185969cce8aac25e098e515d979c0c68c4b3
4
- data.tar.gz: dbeec047ad6244584a544625cbe08c17fad653a766053c65c01146ca77a7a555
3
+ metadata.gz: c89e229d3f5d6d0a4bb8251ae3b37da48e757d30d5af5b0779c15971c8e9fde9
4
+ data.tar.gz: de43414a5ee1bfd482bcd2780631fbcccf5f6eec9a84ae7c4d635669e95117ee
5
5
  SHA512:
6
- metadata.gz: 6aa1f731ad94c1a624664660d59a41c318deffc15ca84b8a4d16a7851b9a9ae230043f5b1ebd5be4156ae19993770c8a699cb5907f20d91a91153239d6c33354
7
- data.tar.gz: e3306e55678301415b354006c97f8d3aba27c040d12e47ff3780a96865741c75e893bd27c9fb0a2c169aed00e866e7f7c4dc3238c024b3bafe426bea6921eb8e
6
+ metadata.gz: fa1fbdd5436ca3397ac430aeeb741c909f439f99c2feff0a5a6b291bfb2b5eef1f86c977188f1f13dac5d50b37f936ded01a51dc720e34e0c2575a0be3818ce0
7
+ data.tar.gz: 1a57887eda7e18fe83c79e1ebf51cdb02b828eb0df1a8b20c2b5d790077841661b865d82cca2d470af39ec6615d33be9b417aba45d9de33253751b726a4d4e4f
@@ -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.1)
4
+ rakuten_securities_scraper (0.1.6)
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,37 @@
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
23
  Rakuten Securities Scraper / 楽天証券スクレイパー
24
+
25
+ ## Introduction
26
+
4
27
  This gem is providing scraper methods for everyone to be able to make stock trading applications without writing scraper codes.
5
28
 
29
+ It features:
30
+
31
+ - Get all trading histories
32
+ - Auto Buying (future)
33
+ - Auto Selling (future)
34
+
6
35
  ## Installation
7
36
 
8
37
  Add this line to your application's Gemfile:
@@ -31,15 +60,22 @@ Or install it yourself as:
31
60
  ## Get All Trade History
32
61
  puts data.all_history
33
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
70
+
34
71
  ```
35
72
 
36
73
  ## Development
37
74
 
38
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.
39
76
 
40
- 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).
41
78
 
42
79
  ## Contributing
43
80
 
44
81
  Bug reports and pull requests are welcome on GitHub at https://github.com/elsoul/rakuten_securities_scraper.
45
-
@@ -11,6 +11,158 @@ 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
+ codes.each do |code|
38
+ driver.find_element(name: "addAnchor").click
39
+ sleep 1
40
+ driver.switch_to.frame driver.find_element(:id, "TB_iframeContent")
41
+ result = click_favorite driver, code.to_s
42
+ sleep 1
43
+ puts "hey" if result == "already exist"
44
+ end
45
+ driver.find_element(id: "prc_save_button1").click
46
+ { status: "success" }
47
+ end
48
+
49
+ def delete_favorite page_num
50
+ driver = login
51
+ sleep 2
52
+ driver.action.move_to(driver.find_element(id: "gmenu_domestic_stock")).perform
53
+ sleep 2
54
+ driver.find_element(id: "gmenu_domestic_stock").click
55
+ sleep 2
56
+ driver.find_element(link_text: "お気に入り銘柄").click
57
+ sleep 2
58
+ driver.find_element(link_text: page_num).click
59
+ sleep 2
60
+ driver.find_element(name: "editAnchor").click
61
+ sleep 2
62
+ table = driver.find_element(class_name: "tbl-data-01")
63
+ rows = table.find_elements(xpath: "//tr")
64
+ last_row = rows.size - 2
65
+ rows[2..last_row].each do |row|
66
+ driver.find_element(id: "line_delete_button_1").click
67
+ driver.switch_to.alert.accept
68
+ sleep 1
69
+ end
70
+ driver.find_element(id: "prc_save_button1").click
71
+ { status: "success" }
72
+ end
73
+
74
+ def click_favorite driver, code
75
+ sleep 2
76
+ driver.find_element(name: "dscrCdNm").clear
77
+ driver.find_element(name: "dscrCdNm").send_keys code
78
+ driver.find_element(name: "dscrCdNm").send_keys(:enter)
79
+ sleep 2
80
+ rows = driver.find_elements(xpath: "//tr")
81
+ value = ""
82
+ num = 0
83
+ rows[3..rows.size - 1].each_with_index do |f, i|
84
+ cells = f.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
85
+ value = i if cells[1] == code and cells[3] == "東証"
86
+ num += 1
87
+ end
88
+ while value == ""
89
+ driver.find_element(xpath: "//*[@id='str-main-inner']/table/tbody/tr/td/table/tbody/tr/td/form/ul/li[2]/a").click
90
+ rows = driver.find_elements(xpath: "//tr")
91
+ rows[3..rows.size - 1].each_with_index do |f, i|
92
+ cells = f.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
93
+ value = i + num - 1 if cells[1] == code and cells[3] == "東証"
94
+ end
95
+ end
96
+ driver.find_element(xpath: "//*[@id='#{value}']").click
97
+ sleep 2
98
+ driver.find_element(xpath: "//*[@id='str-main-inner']/table/tbody/tr/td/table/tbody/tr/td/form/div[3]/ul/li/a/img").click
99
+ begin
100
+ return "already exist" if driver.find_element(xpath: "//*[@id='err_msg']").text.include? "すでに登録済みの銘柄が含まれています。"
101
+ rescue
102
+ end
103
+ driver
104
+ end
105
+
106
+ def todays_order
107
+ driver = get_selenium_driver(:chrome)
108
+ wait = Selenium::WebDriver::Wait.new(timeout: 100)
109
+ url = "https://www.rakuten-sec.co.jp/ITS/V_ACT_Login.html"
110
+ driver.get url
111
+ driver.find_element(id: "form-login-id").send_keys @login[:login_id]
112
+ driver.find_element(id: "form-login-pass").send_keys @login[:login_pw]
113
+ driver.find_element(id: "login-btn").click
114
+ sleep 2
115
+ driver.action.move_to(driver.find_element(id: "gmenu_domestic_stock")).perform
116
+ sleep 2
117
+ driver.find_element(id: "gmenu_domestic_stock").click
118
+ sleep 2
119
+ driver.find_element(id: "nav-sub-menu-order-arrow").click
120
+ wait.until { driver.find_element(xpath: "//*[@id='str-main-inner']/table/tbody/tr/td/form/div[2]/div/ul/li[3]/a") }
121
+ driver.find_element(xpath: "//*[@id='str-main-inner']/table/tbody/tr/td/form/div[2]/div/ul/li[3]/a").click
122
+ sleep 2
123
+ span_select = Selenium::WebDriver::Support::Select.new(driver.find_element(:id, "orderStatus"))
124
+ span_select.select_by(:value, "5")
125
+ sleep 1
126
+ driver.find_element(css: "input[type='image']").click
127
+ sleep 2
128
+ tables = driver.find_elements(xpath: "//tr")
129
+ page_num = driver.find_element(class_name: "mtext").text.scan(/(.+)件中/)[0][0].to_i
130
+ row_nums = (21..(21 + (page_num * 3) - 1)).to_a
131
+ records = []
132
+ row_nums.each_slice(3).to_a.map do |col_num|
133
+ detail = {}
134
+ tables[col_num[0]..col_num[2]].map.with_index do |row, i|
135
+ cells = row.find_elements(:css, "td").map(&:text)
136
+ case i
137
+ when 0
138
+ detail[:order_id] = cells[0] if cells[0]
139
+ detail[:order_status] = cells[1] if cells[1]
140
+ detail[:order_date] = cells[2] if cells[2]
141
+ detail[:stock_name] = cells[3].split("\n")[0] if cells[3]
142
+ detail[:code] = cells[3].split("\n")[1].split(" ")[0] if cells[3]
143
+ detail[:market] = cells[3].split("\n")[1].split(" ")[1] if cells[3]
144
+ detail[:trade_type] = cells[4] if cells[4]
145
+ detail[:buy_sell] = cells[5] if cells[5]
146
+ detail[:order_amount] = cells[7] if cells[7]
147
+ detail[:unit_price] = cells[8] if cells[8]
148
+ detail[:executed_price] = cells[8] if cells[8]
149
+ when 1
150
+ detail[:order_condition] = cells[2] if cells[2]
151
+ detail[:account_type] = cells[3] if cells[3]
152
+ detail[:executed_price] = cells[5] if cells[5]
153
+ detail[:fee] = cells[6] if cells[6]
154
+ else
155
+ detail[:order_expire_date] = cells[2] if cells[2]
156
+ detail[:order_type] = cells[3] if cells[3]
157
+ end
158
+ records << detail
159
+ end
160
+ end
161
+ records
162
+ ensure
163
+ driver.quit
164
+ end
165
+
14
166
  def all_history
15
167
  driver = get_selenium_driver(:chrome)
16
168
  wait = Selenium::WebDriver::Wait.new(timeout: 100)
@@ -47,9 +199,11 @@ module RakutenSecuritiesScraper
47
199
  driver.find_element(id: "login-btn").click
48
200
  wait.until { driver.find_element(id: "header-menu-button-asset") }
49
201
  driver.action.move_to(driver.find_element(id: "header-menu-button-asset")).perform
202
+ sleep 2
50
203
  wait.until { driver.find_element(xpath: "/html/body/div[2]/div/div/div[2]/ul[1]/li[1]/ul/li[1]/a") }
204
+ sleep 2
51
205
  driver.find_element(xpath: "/html/body/div[2]/div/div/div[2]/ul[1]/li[1]/ul/li[1]/a").click
52
-
206
+ sleep 3
53
207
  driver.find_element(css: "input[type='image']").click
54
208
  sleep 2
55
209
  rows = driver.find_elements(xpath: "//tr")
@@ -66,7 +220,7 @@ module RakutenSecuritiesScraper
66
220
  def trade_table_data driver, page_num
67
221
  run_times = page_num.divmod(20)
68
222
  trade_records = []
69
- (1..run_times[0]-1).each do |f|
223
+ (1..run_times[0] - 1).each do |f|
70
224
  rows = driver.find_elements(xpath: "//tr")
71
225
  rows[10..29].map do |row|
72
226
  cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
@@ -89,14 +243,19 @@ module RakutenSecuritiesScraper
89
243
  tax_type: cells[7].split("\n")[1],
90
244
  total_price: cells[8]
91
245
  }
92
- return trade_records if page_num < 20
93
246
  end
247
+ puts trade_records
248
+ return trade_records if page_num < 20
94
249
  driver.find_element(link: "次の20件").click
95
250
  end
96
251
  sleep 2
97
- driver.find_element(link: "次の#{run_times[1]}件").click
252
+ begin
253
+ driver.find_element(link: "次の#{run_times[1]}件").click
254
+ rescue
255
+ return trade_records
256
+ end
98
257
  rows = driver.find_elements(xpath: "//tr")
99
- rows[10.."1#{run_times[1]}".to_i-1].map do |row|
258
+ rows[10.."1#{run_times[1]}".to_i - 1].map do |row|
100
259
  cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
101
260
  trade_records << {
102
261
  bit_date: cells[0].split("\n")[0],
@@ -1,3 +1,3 @@
1
1
  module RakutenSecuritiesScraper
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -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,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rakuten_securities_scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.7
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: []
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
13
69
  description: This gem is providing scraper methods for everyone to be able to make
14
70
  stock trading applications without writing scraper codes.
15
71
  email:
@@ -24,6 +80,7 @@ files:
24
80
  - ".travis.yml"
25
81
  - Gemfile
26
82
  - Gemfile.lock
83
+ - LICENSE
27
84
  - README.md
28
85
  - Rakefile
29
86
  - bin/console