sbi-security 0.0.5 → 0.0.6
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 +4 -4
- data/lib/sbi/security/crawler.rb +36 -28
- data/lib/sbi/security/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 276da7a24142d8afb718cecab458f226dc0e5339
|
4
|
+
data.tar.gz: 85bd5f0ead7b83bf2f26bf5dab7275f70f6af16f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79c919bd54f9baffc7ee701b5abf2462b79a322ad195ce05e3b87b6d8b3cd31d332e61f3ae7d4f70c9f535617c0b5a0264c65cebaa83498c29adfe5258c4127e
|
7
|
+
data.tar.gz: ca8a8b2e4d0404961bb8f093f45b3cda3083a09db3f3d9a99e2e8da66da28871a6cd0896e07b3e8ad7d9a741bcfd6d7ac118acd5e21b25985d5fbbefa4c1f3d4
|
data/lib/sbi/security/crawler.rb
CHANGED
@@ -44,41 +44,49 @@ module Sbi::Security
|
|
44
44
|
find(:xpath, "//input[@id='top_stock_sec']").set code
|
45
45
|
find("img[title='株価検索']").click
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
begin
|
48
|
+
# SBI security has XHR for fetching information. Need to wait until page finish to emulate JavaScript.
|
49
|
+
loop do
|
50
|
+
if find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text != "--"
|
51
|
+
break
|
52
|
+
end
|
53
|
+
sleep 0.1
|
51
54
|
end
|
52
|
-
|
55
|
+
rescue Capybara::ElementNotFound
|
56
|
+
retry
|
53
57
|
end
|
54
58
|
|
55
|
-
|
56
|
-
|
59
|
+
begin
|
60
|
+
price_ratio, price_ratio_percentage = all(:xpath, "//td[@id='MTB0_1']/p/span").map { |td| td.text.gsub(/,/, "") }
|
61
|
+
start_price, end_price, highest_price, total_stock, lowest_price, total_price = all(:xpath, "//table[@class='tbl690']/tbody/tr/td/p/span[@class='fm01']").map { |td| td.text.gsub(/,/, "") }
|
57
62
|
|
58
|
-
|
59
|
-
|
63
|
+
order_books = all(:xpath, "//div[@class='itaTbl02']/table/tbody/tr").drop(1).map do |tr|
|
64
|
+
sell_volume, price, buy_volume = tr.all(:xpath, "./td").map(&:text)
|
60
65
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
66
|
+
OrderBook.new(
|
67
|
+
volume: sell_volume.empty? ? buy_volume : sell_volume,
|
68
|
+
price: price,
|
69
|
+
type: sell_volume.empty? ? "buy" : "sell"
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
Stock.new(
|
74
|
+
code: code,
|
75
|
+
name: find(:xpath, "//h3/span[@class='fxx01']").text,
|
76
|
+
price: find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text.gsub(/,/, ""),
|
77
|
+
price_ratio: empty_string_to_num(price_ratio).to_i,
|
78
|
+
price_ratio_percentage: empty_string_to_num(price_ratio_percentage).to_f,
|
79
|
+
start_price: start_price.to_i,
|
80
|
+
end_price: end_price,
|
81
|
+
highest_price: highest_price.to_i,
|
82
|
+
total_stock: total_stock.to_i,
|
83
|
+
lowest_price: lowest_price.to_i,
|
84
|
+
total_price: total_price.to_i * 1000,
|
85
|
+
order_books: order_books
|
65
86
|
)
|
87
|
+
rescue Selenium::WebDriver::Error::StaleElementReferenceError
|
88
|
+
retry
|
66
89
|
end
|
67
|
-
|
68
|
-
Stock.new(
|
69
|
-
code: code,
|
70
|
-
name: find(:xpath, "//h3/span[@class='fxx01']").text,
|
71
|
-
price: find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text.gsub(/,/, ""),
|
72
|
-
price_ratio: empty_string_to_num(price_ratio).to_i,
|
73
|
-
price_ratio_percentage: empty_string_to_num(price_ratio_percentage).to_f,
|
74
|
-
start_price: start_price.to_i,
|
75
|
-
end_price: end_price,
|
76
|
-
highest_price: highest_price.to_i,
|
77
|
-
total_stock: total_stock.to_i,
|
78
|
-
lowest_price: lowest_price.to_i,
|
79
|
-
total_price: total_price.to_i * 1000,
|
80
|
-
order_books: order_books
|
81
|
-
)
|
82
90
|
end
|
83
91
|
|
84
92
|
private
|
data/lib/sbi/security/version.rb
CHANGED