hotel_price 0.3.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/lib/hotel_price/rakuten/rakuten_api.rb +19 -4
- data/lib/hotel_price/rakuten/rakuten_scraper.rb +16 -2
- data/lib/hotel_price/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29b85ee0e8478b226d95b31d1f1eb18ce0d9165bf5cb7cf4d4f3165e906c35f8
|
4
|
+
data.tar.gz: cff34413dc55092d53228bc8048c2d669f26357887deeb264d178d54e4fef048
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 930bf9bd9fad63ed2655567a5baf09fab6f5b6b866f1b95e2470fa0dca922bbd886cd9e72133d40d974bc72ed64ace90170bee92e7c2b32b49ca009e860fbcd1
|
7
|
+
data.tar.gz: dd6bb55154eb12b56d87f21dda4580fcb7d361e6def1fd13a6c762f20a67993607534d977b2f9d407037f46288b8f9154cfbd05483e995a8dee4074ad886b0df
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -99,6 +99,7 @@ module HotelPrice::Rakuten
|
|
99
99
|
uri = URI.parse("https://app.rakuten.co.jp/services/api/Travel/HotelDetailSearch/20131024?hotelNo=" + @config[:rakuten_hotel_id].to_s + "&applicationId=" + @config[:rakuten_api_key].to_s + "&datumType=1&responseType=large")
|
100
100
|
json = Net::HTTP.get(uri)
|
101
101
|
result = JSON.parse(json)
|
102
|
+
puts uri
|
102
103
|
return "ホテル情報がありませんでした。" if result["error"] == "not_found"
|
103
104
|
return result["error_description"] if result["error"] == "wrong_parameter"
|
104
105
|
result["hotels"][0].each do |_key, field|
|
@@ -174,18 +175,32 @@ module HotelPrice::Rakuten
|
|
174
175
|
uri = URI.parse(url)
|
175
176
|
json = Net::HTTP.get(uri)
|
176
177
|
result = JSON.parse(json)
|
177
|
-
|
178
|
+
i = 1
|
178
179
|
result["hotels"].each do |key, _value|
|
179
180
|
if @config[:rakuten_hotel_id] == key["hotel"][0]["hotelBasicInfo"]["hotelNo"].to_s
|
180
181
|
return {
|
181
|
-
area_rank:
|
182
|
+
area_rank: i.to_i + ((body[:page_num].to_i - 1) * 30),
|
182
183
|
hotel_name: key["hotel"][0]["hotelBasicInfo"]["hotelName"],
|
183
184
|
status: "found"
|
184
185
|
}
|
185
186
|
end
|
186
|
-
|
187
|
+
i += 1
|
187
188
|
end
|
188
|
-
{ status: "
|
189
|
+
{ status: "not_found" }
|
190
|
+
end
|
191
|
+
|
192
|
+
def get_page_num(params = {})
|
193
|
+
body = {
|
194
|
+
middle_class_code: hotel.middle_class_code,
|
195
|
+
small_class_code: hotel.small_class_code,
|
196
|
+
detail_class_code: hotel.detail_class_code
|
197
|
+
}
|
198
|
+
url = "https://app.rakuten.co.jp/services/api/Travel/SimpleHotelSearch/20170426?applicationId=#{@config[:rakuten_api_key]}&largeClassCode=japan&middleClassCode=#{body[:middle_class_code]}&smallClassCode=#{body[:small_class_code]}&detailClassCode=#{body[:detail_class_code]}"
|
199
|
+
puts url
|
200
|
+
uri = URI.parse(url)
|
201
|
+
json = Net::HTTP.get(uri)
|
202
|
+
result = JSON.parse(json)
|
203
|
+
result["pagingInfo"]["pageCount"]
|
189
204
|
end
|
190
205
|
end
|
191
206
|
end
|
@@ -61,13 +61,27 @@ module HotelPrice::Rakuten
|
|
61
61
|
plan_num.size
|
62
62
|
end
|
63
63
|
|
64
|
+
def self.get_detail_class_code rakuten_hotel_id
|
65
|
+
driver = self.get_selenium_driver
|
66
|
+
driver.get "https://hotel.travel.rakuten.co.jp/hinfo/?f_no=#{rakuten_hotel_id}"
|
67
|
+
{
|
68
|
+
status: "found",
|
69
|
+
detail_class_code: driver.find_element(id: "breadcrumbs-detail").attribute("href").match(/\/.\./).to_s.gsub("/", "").gsub(".", "")
|
70
|
+
}
|
71
|
+
rescue
|
72
|
+
{
|
73
|
+
status: "not_found",
|
74
|
+
detail_class_code: ""
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
64
78
|
def self.get_selenium_driver
|
65
79
|
# firefox_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
|
66
80
|
# @driver = Selenium::WebDriver.for(:remote, url: "http://hub:4444/wd/hub", desired_capabilities: firefox_capabilities)
|
67
|
-
|
81
|
+
|
68
82
|
options = Selenium::WebDriver::Firefox::Options.new
|
69
83
|
options.add_argument("-headless")
|
70
|
-
Selenium::WebDriver.for :firefox
|
84
|
+
Selenium::WebDriver.for :firefox, options: options
|
71
85
|
end
|
72
86
|
|
73
87
|
end
|
data/lib/hotel_price/version.rb
CHANGED