hotel_price 0.3.1 → 0.3.2

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: a258d3e3cd27cf75ec732a05891c6cc464603e505e897c4160654c389851b08b
4
- data.tar.gz: 0111e2c99abd43c92e440b0ee798f4c9633ae5887c87e97e6d700b8613ee8ad9
3
+ metadata.gz: 672b35ba401f15c898aec3704672a2f44c036ed6ead4fe58141eb6b733cedb4e
4
+ data.tar.gz: 64e76de7703a063114353638292c2beb15654eb43b70fddbf405f2ce303cfcca
5
5
  SHA512:
6
- metadata.gz: af2482c3ee4b4eadb3d101d4f075ca76d241600ee1c7652495d1bd53fc6954589923a371d09c97855d00794f87126bd797b780ff5e6731ca82dcca670a83d89a
7
- data.tar.gz: 8239b9ce0695efa32ac9cb0dbc58e664d03411f6f419bf6cd485b539dc910a7667706e1165a40660b9771b617b7eec6346bc6b0346694804c8f7d05c6f77d30f
6
+ metadata.gz: 6d22b791dea64cdbb7b7d37b6b3903d5bddf7091032e0b47c3015c0b1fc29510392fe8719ace887ba788ce6c2c0df84d5b8a5d6d2a245b5e525f1457f78b598c
7
+ data.tar.gz: bf780e075c09d2bf1afa8d7b9309ac61376d70ad4d8b9b4da29b17e72aaaf85553fd40ae211141647eda2b15c867497c3b6ce4422560d209277a341e53373702
data/.rubocop.yml CHANGED
@@ -92,9 +92,8 @@ Style/GuardClause:
92
92
 
93
93
  # rake タスクの順序の hash は rocket を許可する
94
94
  Style/HashSyntax:
95
- Exclude:
96
- - "**/*.rake"
97
- - "Rakefile"
95
+ EnforcedStyle: ruby19
96
+
98
97
 
99
98
  # 条件式の方を意識させたい場合には後置の if/unless を使わない方が分かりやすい
100
99
  Style/IfUnlessModifier:
@@ -222,4 +221,4 @@ Style/MutableConstant:
222
221
  Enabled: false
223
222
 
224
223
  Lint/NonDeterministicRequireOrder:
225
- Enabled: false
224
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,13 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.3.0)
4
+ hotel_price (0.3.1)
5
+ nokogiri (~> 1.10.9)
6
+ selenium-webdriver (~> 3.141)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
8
10
  specs:
9
11
  childprocess (3.0.0)
10
12
  diff-lcs (1.3)
13
+ mini_portile2 (2.4.0)
14
+ nokogiri (1.10.9)
15
+ mini_portile2 (~> 2.4.0)
11
16
  rake (13.0.1)
12
17
  rspec (3.9.0)
13
18
  rspec-core (~> 3.9.0)
@@ -35,7 +40,6 @@ DEPENDENCIES
35
40
  hotel_price!
36
41
  rake (>= 12.3.3)
37
42
  rspec (~> 3.0)
38
- selenium-webdriver (~> 3.141)
39
43
 
40
44
  BUNDLED WITH
41
45
  2.1.4
data/hotel_price.gemspec CHANGED
@@ -31,5 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "bundler", "~> 2.0"
32
32
  spec.add_development_dependency "rake", ">= 12.3.3"
33
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
- spec.add_development_dependency "selenium-webdriver", "~> 3.141"
34
+ spec.add_runtime_dependency "nokogiri", "~> 1.10.9"
35
+ spec.add_runtime_dependency "selenium-webdriver", "~> 3.141"
35
36
  end
@@ -9,7 +9,6 @@ module HotelPrice::Booking
9
9
  url = "https://www.booking.com/hotel/jp/#{booking_hotel_id}.ja.html?#{query_string}"
10
10
  driver = self.get_selenium_driver
11
11
  driver.get(url)
12
- puts url
13
12
  sleep 2
14
13
 
15
14
  data = driver.find_elements(:class_name, "hprt-table")
@@ -18,7 +17,10 @@ module HotelPrice::Booking
18
17
  return { date: date, min_price: 0 } if price_box.empty?
19
18
  price = price_box.first.text.delete("^0-9").to_i
20
19
 
21
- { date: date, price: price }
20
+ hotel_name = driver.find_elements(:class_name, "hp__hotel-type-badge").first.text
21
+ room_name = driver.find_elements(:class_name, "hprt-ws-roomtype-link").first.text
22
+
23
+ { date: date, min_price: price, hotel_name: hotel_name, room_name: room_name }
22
24
  end
23
25
 
24
26
  def self.make_query_string(checkin_date, num_adults)
@@ -1,26 +1,35 @@
1
1
  module HotelPrice::Jalan
2
+ require "nokogiri"
3
+ require "open-uri"
2
4
  class JalanAPI
3
- def initialize api_key
4
- @api_key = api_key
5
+ def initialize params
6
+ @config = {
7
+ jalan_hotel_id: params[:jalan_hotel_id] ||= 0,
8
+ jalan_api_key: params[:jalan_api_key] ||= ENV["JALAN_API_KEY"]
9
+ }
5
10
  end
6
11
 
7
12
  def test
8
- @api_key
13
+ @config[:jalan_api_key]
9
14
  end
10
15
 
11
- def get_price jalan_hotel_id, checkin_date, adult_num
12
- url = "http://jws.jalan.net/APIAdvance/StockSearch/V1/?key=#{@api_key}&h_id=#{jalan_hotel_id}&stay_date=#{checkin_date}&stay_count=1&adult_num=#{adult_num}&count=1"
16
+ def get_min_price params
17
+ url = "http://jws.jalan.net/APIAdvance/StockSearch/V1/?key=#{@config[:jalan_api_key]}&h_id=#{@config[:jalan_hotel_id]}&stay_date=#{params[:checkin_date]}&stay_count=1&adult_num=#{params[:adult_num]}&count=1"
13
18
  puts url
14
19
  doc = Nokogiri::XML(open(url))
15
20
  if doc.css("NumberOfResults").text == "0"
16
21
  {
17
22
  date: DateTime.now.strftime("%Y-%m-%d"),
23
+ jalan_hotel_id: @config[:jalan_hotel_id],
24
+ checkin_date: params[:checkin_date],
18
25
  plan_num: 0,
19
26
  min_price: 0
20
27
  }
21
28
  else
22
29
  {
23
30
  date: DateTime.now.strftime("%Y-%m-%d"),
31
+ jalan_hotel_id: @config[:jalan_hotel_id],
32
+ checkin_date: params[:checkin_date],
24
33
  hotel_name: doc.css("Plan").css("Hotel HotelName").text,
25
34
  room_name: doc.css("Plan").css("RoomName").text,
26
35
  plan_name: doc.css("Plan").css("PlanName").text,
@@ -7,6 +7,56 @@ module HotelPrice::Rakuten
7
7
  }
8
8
  end
9
9
 
10
+ def get_min_price params
11
+ params[:breakfast] ||= ""
12
+ try = 0
13
+ begin
14
+ base_url = "https://app.rakuten.co.jp/services/api/Travel/VacantHotelSearch/20131024?format=json&sort=%2BroomCharge&searchPattern=1"
15
+ url = [base_url, "&applicationId=", @config[:rakuten_api_key], "&adultNum=", params[:adult_num].to_s, "&checkinDate=", params[:checkin_date].to_s, "&checkoutDate=", (Date.parse(params[:checkin_date]) + 1).strftime("%Y-%m-%d"), "&hotelNo=", @config[:rakuten_hotel_id].to_s, "&squeezeCondition=", params[:breakfast]].join
16
+ json = Net::HTTP.get(URI.parse(url))
17
+ result = JSON.parse(json)
18
+ try = 0
19
+ begin
20
+ data_hash = if result["error"] == "not_found"
21
+ {
22
+ date: DateTime.now.strftime("%Y-%m-%d"),
23
+ checkin_date: params[:checkin_date],
24
+ rakuten_hotel_id: params[:rakuten_hotel_id],
25
+ adult_num: params[:adult_num],
26
+ breakfast: params[:breakfast],
27
+ plan_num: 0,
28
+ min_price: 0
29
+ }
30
+ elsif result["error"] == "wrong_parameterd"
31
+ "入力した値が正しくありません。"
32
+ else
33
+ {
34
+ date: DateTime.now.strftime("%Y-%m-%d"),
35
+ checkin_date: result["hotels"][0]["hotel"][1]["roomInfo"][1]["dailyCharge"]["stayDate"],
36
+ rakuten_hotel_id: params[:rakuten_hotel_id],
37
+ hotel_name: result["hotels"][0]["hotel"][0]["hotelBasicInfo"]["hotelName"],
38
+ adult_num: params[:adult_num],
39
+ breakfast: params[:breakfast],
40
+ plan_num: result["pagingInfo"]["recordCount"],
41
+ room_name: result["hotels"][0]["hotel"][1]["roomInfo"][0]["roomBasicInfo"]["roomName"],
42
+ plan_name: result["hotels"][0]["hotel"][1]["roomInfo"][0]["roomBasicInfo"]["planName"],
43
+ min_price: result["hotels"][0]["hotel"][1]["roomInfo"][1]["dailyCharge"]["rakutenCharge"]
44
+ }
45
+ end
46
+ rescue StandardError => e
47
+ try += 1
48
+ sleep 2
49
+ puts "エラー発生。リトライします。\n #{e.message}"
50
+ retry if try < 5
51
+ end
52
+ rescue StandardError => e
53
+ try += 1
54
+ sleep 5
55
+ retry if try < 5
56
+ end
57
+ data_hash
58
+ end
59
+
10
60
  def hotel_info
11
61
  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")
12
62
  json = Net::HTTP.get(uri)
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotel_price
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fumitake Kawasaki
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: nokogiri
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.10.9
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.10.9
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: selenium-webdriver
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -60,7 +74,7 @@ dependencies:
60
74
  - - "~>"
61
75
  - !ruby/object:Gem::Version
62
76
  version: '3.141'
63
- type: :development
77
+ type: :runtime
64
78
  prerelease: false
65
79
  version_requirements: !ruby/object:Gem::Requirement
66
80
  requirements: