hotel_price 0.5.6 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  require_relative "./jalan/jalan_api"
2
- require_relative "./jalan/jalan_console"
3
2
  require_relative "./jalan/jalan_scraper"
4
3
 
5
4
  module HotelPrice
@@ -15,7 +15,7 @@ module HotelPrice::Jalan
15
15
 
16
16
  def get_min_price params
17
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"
18
- doc = Nokogiri::XML(open(url))
18
+ doc = Nokogiri::XML(url)
19
19
  if doc.css("NumberOfResults").text == "0"
20
20
  {
21
21
  date: DateTime.now.strftime("%Y-%m-%d"),
@@ -1,11 +1,17 @@
1
1
  module HotelPrice::Jalan
2
2
  class JalanScraper
3
- def self.get_price(jalan_hotel_id, checkin_date, num_adults, mode = 0)
3
+ @mode
4
+
5
+ def initialize(mode = :chrome)
6
+ @mode = mode
7
+ end
8
+
9
+ def get_price(jalan_hotel_id, checkin_date, num_adults)
4
10
  date = DateTime.now.strftime("%Y-%m-%d")
5
11
 
6
12
  query_string = make_query_string(checkin_date.to_s, num_adults)
7
13
  url = "https://www.jalan.net/yad#{jalan_hotel_id}/plan/?screenId=UWW3101&yadNo=#{jalan_hotel_id}&#{query_string}"
8
- driver = HotelPrice.get_selenium_driver mode
14
+ driver = HotelPrice.get_selenium_driver @mode
9
15
  driver.get(url)
10
16
  sleep 2
11
17
  @price_box = []
@@ -20,25 +26,26 @@ module HotelPrice::Jalan
20
26
  plan_name: f.find_element(class_name: "p-planCassette__header").text
21
27
  }
22
28
  rescue StandardError
29
+ { date: date, min_price: 0 }
23
30
  end
24
31
  end
25
- @price_box.sort_by { |_a, _b, c| c }.reverse.first
32
+ @price_box.sort_by { |_a, _b, c| c }.reverse.first || { date: date, min_price: 0 }
26
33
  rescue StandardError
27
34
  { date: date, min_price: 0 }
28
35
  end
29
36
 
30
- def self.make_query_string(checkin_date, num_adults)
37
+ def make_query_string(checkin_date, num_adults)
31
38
  cd_args = make_date_args checkin_date
32
39
  na_args = make_num_adults_arg num_adults
33
40
  "rootCd=7701&callbackHistFlg=1&contHideFlg=1&reSearchFlg=1&roomCrack=100000&smlCd=121108&distCd=01&#{cd_args}&stayCount=1&roomCount=1&#{na_args}&minPrice=0&maxPrice=999999"
34
41
  end
35
42
 
36
- def self.make_date_args checkin_date
43
+ def make_date_args checkin_date
37
44
  Date.parse checkin_date rescue return ""
38
45
  Date.parse(checkin_date).strftime("stayYear=%Y&stayMonth=%m&stayDay=%d")
39
46
  end
40
47
 
41
- def self.make_num_adults_arg num_adults
48
+ def make_num_adults_arg num_adults
42
49
  return "" if num_adults.to_i < 1
43
50
  "adultNum=#{num_adults}"
44
51
  end
@@ -1,5 +1,4 @@
1
1
  require_relative "./rakuten/rakuten_api"
2
- require_relative "./rakuten/rakuten_console"
3
2
  require_relative "./rakuten/rakuten_scraper"
4
3
 
5
4
  module HotelPrice
@@ -14,7 +14,7 @@ module HotelPrice::Rakuten
14
14
  result = JSON.parse(json)
15
15
  if result["error"] == "not_found"
16
16
  {
17
- date: DateTime.now.strftime("%Y-%m-%d"),
17
+ date: Time.now.strftime("%Y-%m-%d"),
18
18
  checkin_date: checkin_date,
19
19
  rakuten_hotel_id: @config[:rakuten_hotel_id],
20
20
  adult_num: num_adults,
@@ -45,118 +45,5 @@ module HotelPrice::Rakuten
45
45
  "format=json&sort=%2BroomCharge&searchPattern=1&applicationId=#{@config[:rakuten_api_key]}&hotelNo=#{rakuten_hotel_id}&adultNum=#{num_adults}&checkinDate=#{checkin_date}&checkoutDate=#{checkout_date}&squeezeCondition="
46
46
  end
47
47
 
48
-
49
- def hotel_info
50
- 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")
51
- json = Net::HTTP.get(uri)
52
- result = JSON.parse(json)
53
- return "ホテル情報がありませんでした。" if result["error"] == "not_found"
54
- return result["error_description"] if result["error"] == "wrong_parameter"
55
- result["hotels"][0].each do |_key, field|
56
- field[0].each do |_, value|
57
- @data_hash = {
58
- rakuten_hotel_id: value["hotelNo"],
59
- hotel_name: value["hotelName"],
60
- room_price_min: value["hotelMinCharge"],
61
- lat: value["latitude"],
62
- lon: value["longitude"],
63
- tel: value["telephoneNo"],
64
- zip_code: value["postalCode"],
65
- prefecture: value["address1"],
66
- address1: value["address2"],
67
- fax: value["faxNo"],
68
- access: value["access"],
69
- parking_info: value["parkingInformation"],
70
- near_station: value["nearestStation"],
71
- hotel_img_url: value["hotelImageUrl"],
72
- rakuten_review_count: value["reviewCount"],
73
- rakuten_review_avg: value["reviewAverage"].to_f
74
- }
75
- end
76
- end
77
- result["hotels"][0].each do |_key, field|
78
- field[1].each do |_, value|
79
- @data_hash[:rakuten_service_review] = value["serviceAverage"].to_f
80
- @data_hash[:rakuten_location_review] = value["locationAverage"].to_f
81
- @data_hash[:rakuten_room_review] = value["roomAverage"].to_f
82
- @data_hash[:rakuten_equipment_review] = value["equipmentAverage"].to_f
83
- @data_hash[:rakuten_bath_review] = value["bathAverage"].to_f
84
- @data_hash[:rakuten_meal_review] = value["mealAverage"].to_f
85
- end
86
- end
87
- result["hotels"][0].each do |_key, field|
88
- field[2].each do |_, value|
89
- @data_hash[:middle_class_code] = value["middleClassCode"].to_s
90
- @data_hash[:small_class_code] = value["smallClassCode"].to_s
91
- @data_hash[:area_name] = value["areaName"].to_s
92
- @data_hash[:hotel_class_code] = value["hotelClassCode"].to_s
93
- @data_hash[:checkin_time] = value["checkinTime"].to_s
94
- @data_hash[:checkout_time] = value["checkoutTime"].to_s
95
- @data_hash[:last_checkin_time] = value["lastCheckinTime"].to_s
96
- end
97
- end
98
- result["hotels"][0].each do |_key, field|
99
- field[3].each do |_, value|
100
- @data_hash[:total_room_num] = value["hotelRoomNum"].to_s
101
- room_facilities = []
102
- value["roomFacilities"].each_with_index do |f, i|
103
- room_facilities[i] = f["item"]
104
- end
105
- @data_hash[:room_facilities] = room_facilities
106
- end
107
- end
108
- result["hotels"][0].each do |_key, field|
109
- field[4].each do |_, value|
110
- @data_hash[:hotel_policy_note] = value["note"].to_s
111
- @data_hash[:cancel_policy] = value["cancelPolicy"].to_s
112
- end
113
- end
114
- @data_hash
115
- end
116
-
117
- def search_ranking params
118
- body = {
119
- middle_class_code: params[:middle_class_code],
120
- small_class_code: params[:small_class_code],
121
- detail_class_code: params[:detail_class_code],
122
- page_num: params[:page_num]
123
- }
124
- 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]}&page=#{body[:page_num]}"
125
- uri = URI.parse(url)
126
- json = Net::HTTP.get(uri)
127
- result = JSON.parse(json)
128
- i = 1
129
- result["hotels"].each do |key, _value|
130
- if @config[:rakuten_hotel_id] == key["hotel"][0]["hotelBasicInfo"]["hotelNo"].to_s
131
- return {
132
- status: "found",
133
- hotel_name: key["hotel"][0]["hotelBasicInfo"]["hotelName"],
134
- area_name: body[:area_name],
135
- page_num: params[:page_num],
136
- area_rank: i.to_i + ((body[:page_num].to_i - 1) * 30),
137
- middle_class_code: body[:middle_class_code],
138
- small_class_code: body[:small_class_code],
139
- detail_class_code: body[:detail_class_code]
140
- }
141
- end
142
- i += 1
143
- end
144
- { status: "not_found" }
145
- end
146
-
147
- def get_page_num detail_class_code
148
- hotel = hotel_info
149
- url = "https://app.rakuten.co.jp/services/api/Travel/SimpleHotelSearch/20170426?applicationId=#{@config[:rakuten_api_key]}&largeClassCode=japan&middleClassCode=#{hotel[:middle_class_code]}&smallClassCode=#{hotel[:small_class_code]}&detailClassCode=#{detail_class_code}"
150
- uri = URI.parse(url)
151
- json = Net::HTTP.get(uri)
152
- result = JSON.parse(json)
153
- {
154
- small_class_code: hotel[:small_class_code],
155
- middle_class_code: hotel[:middle_class_code],
156
- detail_class_code: detail_class_code,
157
- area_name: hotel[:area_name].to_s,
158
- page_num: result["pagingInfo"]["pageCount"].to_i
159
- }
160
- end
161
48
  end
162
49
  end
@@ -1,14 +1,17 @@
1
1
  module HotelPrice::Rakuten
2
- ## mode 0 - headless
3
- ## mode 1 - docker selenium
4
- ## mode 2 - debug
5
2
  class RakutenScraper
6
- def self.get_price(rakuten_hotel_id, checkin_date, num_adults, mode = 0)
7
- date = DateTime.now.strftime("%Y-%m-%d")
3
+ @mode
4
+
5
+ def initialize(mode = :chrome)
6
+ @mode = mode
7
+ end
8
+
9
+ def get_price(rakuten_hotel_id, checkin_date, num_adults)
10
+ date = Time.now.strftime("%Y-%m-%d")
8
11
 
9
12
  query_string = make_query_string(checkin_date.to_s, num_adults)
10
13
  url = "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}?#{query_string}"
11
- driver = HotelPrice.get_selenium_driver mode
14
+ driver = HotelPrice.get_selenium_driver @mode
12
15
  driver.get(url)
13
16
  sleep 2
14
17
  driver.find_elements(class_name: "planThumb").first rescue return ""
@@ -22,13 +25,13 @@ module HotelPrice::Rakuten
22
25
  { date: date, min_price: 0 }
23
26
  end
24
27
 
25
- def self.make_query_string(checkin_date, num_adults)
28
+ def make_query_string(checkin_date, num_adults)
26
29
  cd_args = make_date_args checkin_date
27
30
  na_args = make_num_adults_arg num_adults
28
31
  "f_teikei=quick&f_hizuke=&f_hak=&f_dai=japan&f_chu=tokyo&f_shou=nishi&f_sai=&f_tel=&f_target_flg=&f_tscm_flg=&f_p_no=&f_custom_code=&f_search_type=&f_camp_id=&f_static=1&f_rm_equip=&#{cd_args}&f_heya_su=1&#{na_args}"
29
32
  end
30
33
 
31
- def self.make_date_args checkin_date
34
+ def make_date_args checkin_date
32
35
  Date.parse checkin_date rescue return ""
33
36
  t = Date.parse(checkin_date)
34
37
  checkin_arg = t.strftime("f_hi1=%d&f_tuki1=%m&f_nen1=%Y")
@@ -36,84 +39,9 @@ module HotelPrice::Rakuten
36
39
  "#{checkin_arg}&#{checkout_arg}"
37
40
  end
38
41
 
39
- def self.make_num_adults_arg num_adults
42
+ def make_num_adults_arg num_adults
40
43
  return "" if num_adults.to_i <= 1
41
44
  "f_otona_su=#{num_adults}&f_kin2=0&f_kin=&f_s1=0&f_s2=0&f_y1=0&f_y2=0&f_y3=0&f_y4=0"
42
45
  end
43
-
44
- def self.review rakuten_hotel_id, mode = 0
45
- driver = HotelPrice.get_selenium_driver mode
46
- driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_hotel_id}/review.html")
47
- sleep 2
48
- comment_area = driver.find_elements(:class_name, "commentBox")
49
- data = comment_area.map do |f|
50
- if f.find_element(class_name: "user").text.include?("投稿者さん")
51
- username = f.find_element(class_name: "user").text
52
- generation = 0
53
- gender = ""
54
- else
55
- username = f.find_element(class_name: "user").text.match(/(^.+ )/).to_s.strip
56
- generation = f.find_element(class_name: "user").text.match(/\[.+代/).to_s.gsub("[", "").gsub("代", "")
57
- gender = f.find_element(class_name: "user").text.match(/\/../).to_s.gsub("/", "")
58
- end
59
- {
60
- date: f.find_element(class_name: "time").text.gsub("年", "").gsub("月", "").gsub("日", ""),
61
- rate: f.find_element(class_name: "rate").text,
62
- username: username,
63
- generation: generation,
64
- gender: gender,
65
- rakuten_hotel_id: rakuten_hotel_id,
66
- comment: f.find_element(class_name: "commentSentence").text
67
- }
68
- end
69
- driver.quit
70
- data
71
- end
72
-
73
- def self.get_photo_num rakuten_hotel_id, mode = 0
74
- driver = HotelPrice.get_selenium_driver mode
75
- driver.get "https://hotel.travel.rakuten.co.jp/hinfo/#{rakuten_hotel_id}/"
76
- sleep 2
77
- num = driver.find_element(:id, "navPht").text.gsub("写真・動画(", "").gsub(")", "").to_i
78
- driver.quit
79
- num
80
- end
81
-
82
- def self.get_bf_plan_num rakuten_hotel_id, mode = 0
83
- driver = HotelPrice.get_selenium_driver mode
84
- driver.get "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}"
85
- driver.find_element(:id, "focus1").click
86
- driver.find_element(:id, "dh-squeezes-submit").click
87
- sleep 3
88
- plan_num = driver.find_elements(:class, "planThumb")
89
- driver.quit
90
- plan_num.size
91
- end
92
-
93
- def self.get_dayuse_plan_num rakuten_hotel_id, mode = 0
94
- driver = HotelPrice.get_selenium_driver mode
95
- driver.get "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}"
96
- sleep 5
97
- driver.find_element(:id, "du-radio").click
98
- driver.find_element(:id, "dh-submit").click
99
- sleep 5
100
- plan_num = driver.find_elements(:class, "planThumb")
101
- driver.quit
102
- plan_num.size
103
- end
104
-
105
- def self.get_detail_class_code rakuten_hotel_id, mode = 0
106
- driver = HotelPrice.get_selenium_driver mode
107
- driver.get "https://hotel.travel.rakuten.co.jp/hinfo/?f_no=#{rakuten_hotel_id}"
108
- {
109
- status: "found",
110
- detail_class_code: driver.find_element(id: "breadcrumbs-detail").attribute("href").match(/\/.\./).to_s.gsub("/", "").gsub(".", "")
111
- }
112
- rescue StandardError
113
- {
114
- status: "not_found",
115
- detail_class_code: ""
116
- }
117
- end
118
46
  end
119
47
  end
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.5.6"
2
+ VERSION = "0.6.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.5.6
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fumitake Kawasaki
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-04-20 00:00:00.000000000 Z
12
+ date: 2020-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -45,71 +45,71 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '3.0'
48
+ version: 3.9.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '3.0'
55
+ version: 3.9.0
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: activesupport
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 6.0.2.1
62
+ version: 6.0.2.2
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 6.0.2.1
69
+ version: 6.0.2.2
70
70
  - !ruby/object:Gem::Dependency
71
- name: nokogiri
71
+ name: json
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: 1.10.9
76
+ version: 2.3.1
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: 1.10.9
83
+ version: 2.3.1
84
84
  - !ruby/object:Gem::Dependency
85
- name: selenium-webdriver
85
+ name: nokogiri
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '3.141'
90
+ version: 1.10.9
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '3.141'
97
+ version: 1.10.9
98
98
  - !ruby/object:Gem::Dependency
99
- name: json
99
+ name: selenium-webdriver
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: 2.3.0
104
+ version: '3.141'
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: 2.3.0
112
- description: 'Empower World Travel Information Technology '
111
+ version: '3.141'
112
+ description: Webcrawler for checking booking price of travel agencies.
113
113
  email:
114
114
  - fumitake.kawasaki@el-soul.com
115
115
  - jamesoneve@gmail.com
@@ -118,7 +118,6 @@ executables:
118
118
  extensions: []
119
119
  extra_rdoc_files: []
120
120
  files:
121
- - ".DS_Store"
122
121
  - ".gitignore"
123
122
  - ".rspec"
124
123
  - ".rubocop.yml"
@@ -145,20 +144,18 @@ files:
145
144
  - lib/hotel_price/expedia/expedia_scraper.rb
146
145
  - lib/hotel_price/jalan.rb
147
146
  - lib/hotel_price/jalan/jalan_api.rb
148
- - lib/hotel_price/jalan/jalan_console.rb
149
147
  - lib/hotel_price/jalan/jalan_scraper.rb
150
148
  - lib/hotel_price/rakuten.rb
151
149
  - lib/hotel_price/rakuten/rakuten_api.rb
152
- - lib/hotel_price/rakuten/rakuten_console.rb
153
150
  - lib/hotel_price/rakuten/rakuten_scraper.rb
154
151
  - lib/hotel_price/version.rb
155
- homepage: https://github.com/el-fudo/hotel_price
152
+ homepage: https://github.com/elsoul/hotel_price
156
153
  licenses:
157
- - MIT
154
+ - Apache-2.0
158
155
  metadata:
159
- source_code_uri: https://github.com/el-fudo/hotel_price
160
- homepage_uri: https://github.com/el-fudo/hotel_price
161
- changelog_uri: https://github.com/el-fudo/hotel_price
156
+ source_code_uri: https://github.com/elsoul/hotel_price
157
+ homepage_uri: https://github.com/elsoul/hotel_price
158
+ changelog_uri: https://github.com/elsoul/hotel_price
162
159
  post_install_message:
163
160
  rdoc_options: []
164
161
  require_paths:
@@ -167,15 +164,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
164
  requirements:
168
165
  - - ">="
169
166
  - !ruby/object:Gem::Version
170
- version: '0'
167
+ version: 2.7.0
171
168
  required_rubygems_version: !ruby/object:Gem::Requirement
172
169
  requirements:
173
170
  - - ">="
174
171
  - !ruby/object:Gem::Version
175
172
  version: '0'
176
173
  requirements: []
177
- rubygems_version: 3.0.3
174
+ rubygems_version: 3.1.4
178
175
  signing_key:
179
176
  specification_version: 4
180
- summary: Scraping Library to get world hotel price
177
+ summary: Webcrawler for checking booking price of travel agencies.
181
178
  test_files: []