hotel_price 0.6.1 → 0.6.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: bf5eb6642b98241831c3b8fef53d49d36e3831739ab7c71638300a70529cc361
4
- data.tar.gz: 4acb833993a48783844fc6907eafe1845fd445e63bf7412c2b044da40071799c
3
+ metadata.gz: 9f490ac77b152a32bc3b565e71a5a9a2a54eb6e61e16a70c9b75bf0e0c824410
4
+ data.tar.gz: ad252a314e991c0d3a38f16ec90a3a12087cf8be543eb66117bf7123034ce4ee
5
5
  SHA512:
6
- metadata.gz: 9bc3d11d78a5ec661800ee5bd9fe8957d75fde7c5388401bb36882e43b30c9c92c928f3f93048bbd3bdbda604074beb558d1b2da073394d5200606dd32ca3c48
7
- data.tar.gz: b18e19c6bba93f835aca3bf5766b6660d21caaa279a5ea809ac6a80b099a6037f40d4aa9833b875671cb43ad836053b55eafca4a16f36e8445a5846f70c25adb
6
+ metadata.gz: 9fed62c12e9a0c09d7179e3540ebe96ea96f70d907d5c3dcbf78aaef9c8732bdbed0661edf626ee08dd3c71b75638f79678b98198273157ff7f027055459f3ce
7
+ data.tar.gz: 60b7df9db4226018e0aaf95bf24f3f10a0e50c3d651cb920e87a48a76b3c938623bab342955c4d57a8eeaf92ec273b534735e997ea8d00d284a730bd1d2d08cb
@@ -69,6 +69,9 @@ Style/StringHashKeys:
69
69
  - "spec/queries/*.rb"
70
70
  - "*.gemspec"
71
71
 
72
+ Style/RescueModifier:
73
+ Enabled: false
74
+
72
75
  Style/GuardClause:
73
76
  MinBodyLength: 5
74
77
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.5.9)
4
+ hotel_price (0.6.1)
5
5
  activesupport (~> 6.0.2.2)
6
6
  json (~> 2.3.1)
7
7
  nokogiri (~> 1.10.9)
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [![HotelPrice](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://rubygems.org/gems/hotel_price/)
1
+ # Hotel Price
2
+ WebCrawler for checking booking price of travel agencies.
2
3
 
3
4
  <p align="center">
4
5
 
@@ -17,8 +18,6 @@
17
18
  <img alt="" src="https://badgen.net/badge/license/Apache/blue">
18
19
  </a>
19
20
  </p>
20
- # HotelPrice
21
- This Gem is made for ppl who work at travel industry
22
21
 
23
22
  ## Installation
24
23
 
@@ -31,43 +30,131 @@ gem "hotel_price"
31
30
  And then execute:
32
31
 
33
32
  ```bash
34
- $ bundle
33
+ $ bundle
35
34
  ```
36
35
 
37
36
  Or install it yourself as:
38
37
 
39
38
  ```bash
40
- $ gem install hotel_price
39
+ $ gem install hotel_price
41
40
  ```
42
41
 
43
42
  ## Usage
43
+ Initialize Agent Scraper with agent's name and browser mode.
44
44
 
45
- ### Rakuten Travel
45
+ You can choose browser mode below;<br>
46
+ `:chrome`<br>
47
+ `:firefox`<br>
48
+ `:firefox_remote_capabilities`<br>
49
+ (remote_url: "http://hub:4444/wd/hub")<br>
50
+ <br>
46
51
 
47
- #### Rakuten API
48
- Initialize with `rakuten_hotel_id` and `Rakuten Travel API key`
49
- Rakuten Travel API Reference : https://webservice.rakuten.co.jp/api/simplehotelsearch/
52
+ ### Install Chronium for Chrome browser (Mac Homebrew)
53
+ `brew cask install chromium`
50
54
 
55
+ ### Install Geckodriver for Firefox browser
56
+ Download from Mozilla Geckodriver Github<br>
57
+ [https://github.com/mozilla/geckodriver/releases](https://github.com/mozilla/geckodriver/releases)
58
+ <br>
59
+
60
+ <br>
61
+
62
+ ## Agent Availability and Agent Name (at August 2020)
63
+ <br>
64
+ 1. Rakuten Travel -> Rakuten<br>
65
+ 2. Jalan -> Jalan<br>
66
+ 3. Expedia -> Expedia<br>
67
+ 4. Booking.com -> Booking<br>
68
+ 5. Agoda -> Agoda<br>
69
+ <br><br>
70
+
71
+ Argments : `agent_hotel_id`, `YYYY-MM-DD`, `adult_nums`
72
+ <br>
73
+
74
+ `.get_price`
75
+
76
+ method will run web crawler and return minimum price.
77
+
78
+ You can get `agent_hotel_id` from each agent's Official Website.
79
+
80
+ ```ruby
81
+ scraper = HotelPrice::[AgentName]::[AgentName]Scraper.new(:chrome)
82
+ scraper.get_price(agent_hotel_id, checkin_date, adult_nums)
83
+ ```
84
+
85
+ ### Sample Response
86
+ ```ruby
87
+ {
88
+ :date => "2020-08-03",
89
+ :min_price => 5023,
90
+ :hotel_name => "相鉄フレッサイン新橋烏森口(旧:ホテルサンルート新橋)",
91
+ :room_name => "シングル【禁煙】12.7平米120センチ幅シモンズ社製ベッド",
92
+ :plan_name => "NEW 【楽天限定2020】スペシャルサマープラン<食事なし>"
93
+ }
94
+ ```
95
+
96
+ ### Rakuten Travel Scraper
97
+ Official Website<br>
98
+ [https://travel.rakuten.co.jp/](https://travel.rakuten.co.jp/)
99
+
100
+ ```ruby
101
+ scraper = HotelPrice::Rakuten::RakutenScraper.new(:chrome)
102
+ agent_hotel_id = "128552" # e.g 料理旅館 富久潮
103
+ checkin_date = (Date.today + 30.day).to_s
104
+ adult_nums = 1
105
+ scraper.get_price(agent_hotel_id, checkin_date, adult_nums)
106
+ ```
107
+
108
+
109
+ ### Jalan Scraper
110
+ Official Website<br>
111
+ [https://www.jalan.net/](https://www.jalan.net/)
51
112
 
52
113
  ```ruby
53
- hotel = HotelPrice::Rakuten::RakutenAPI.new(
54
- rakuten_hotel_id: "128552",
55
- rakuten_api_key: "api_key"
56
- )
114
+ scraper = HotelPrice::Jalan::JalanScraper.new(:chrome)
115
+ agent_hotel_id = "366371" # e.g 相鉄ホテル
116
+ checkin_date = (Date.today + 30.day).to_s
117
+ adult_nums = 1
118
+ scraper.get_price(agent_hotel_id, checkin_date, adult_nums)
57
119
  ```
58
120
 
59
- Get Hotel Info
121
+
122
+ ### Expedia Scraper
123
+ Official Website<br>
124
+ [https://www.expedia.co.jp/](https://www.expedia.co.jp/)
125
+
126
+ ```ruby
127
+ scraper = HotelPrice::Expedia::ExpediaScraper.new(:chrome)
128
+ agent_hotel_id = "Sapporo-Hotels-Hotel-Sunroute-Sapporo.h5224778" # e.g 相鉄ホテル
129
+ checkin_date = (Date.today + 30.day).to_s
130
+ adult_nums = 1
131
+ scraper.get_price(agent_hotel_id, checkin_date, adult_nums)
132
+ ```
133
+
134
+
135
+ ### Booking.com Scraper
136
+ Official Website<br>
137
+ [http://booking.com/](http://booking.com/)
60
138
 
61
139
  ```ruby
62
- puts hotel.hotel_info
140
+ scraper = HotelPrice::Booking::BookingScraper.new(:chrome)
141
+ agent_hotel_id = "sunroute-sapporo" # e.g 相鉄ホテル
142
+ checkin_date = (Date.today + 30.day).to_s
143
+ adult_nums = 1
144
+ scraper.get_price(agent_hotel_id, checkin_date, adult_nums)
63
145
  ```
64
146
 
65
147
 
66
- ### RakutenScraper
67
- Argments : `rakuten_hotel_id`, `YYYY-MM-DD`, `adult_nums`
148
+ ### Agoda Scraper
149
+ Official Website<br>
150
+ [https://www.agoda.com/](https://www.agoda.com/)
68
151
 
69
152
  ```ruby
70
- HotelPrice::Rakuten::RakutenScraper.get_price("128552", (Date.today + 45.day).to_s, 1)
153
+ scraper = HotelPrice::Agoda::AgodaScraper.new(:chrome)
154
+ agent_hotel_id = "hotel-sunroute-new-sapporo/hotel/sapporo-jp" # e.g 相鉄ホテル
155
+ checkin_date = (Date.today + 30.day).to_s
156
+ adult_nums = 1
157
+ scraper.get_price(agent_hotel_id, checkin_date, adult_nums)
71
158
  ```
72
159
 
73
160
 
@@ -79,12 +166,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
79
166
 
80
167
  ## Contributing
81
168
 
82
- Bug reports and pull requests are welcome on GitHub at https://github.com/el-fudo/hotel_price. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
169
+ Bug reports and pull requests are welcome on GitHub at https://github.com/elsoul/hotel_price. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
83
170
 
84
171
  ## License
85
172
 
86
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
173
+ The gem is available as open source under the terms of the [Apache-2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
87
174
 
88
175
  ## Code of Conduct
89
176
 
90
- Everyone interacting in the HotelPrice project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/el-fudo/hotel_price/blob/master/CODE_OF_CONDUCT.md).
177
+ Everyone interacting in the HotelPrice project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/elsoul/hotel_price/blob/master/CODE_OF_CONDUCT.md).
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Fumitake Kawasaki", "James Neve"]
9
9
  spec.email = ["fumitake.kawasaki@el-soul.com", "jamesoneve@gmail.com"]
10
10
 
11
- spec.summary = "Scraping Library to get world hotel price"
12
- spec.description = "Empower World Travel Information Technology "
11
+ spec.summary = "Webcrawler for checking booking price of travel agencies."
12
+ spec.description = "Webcrawler for checking booking price of travel agencies."
13
13
  spec.homepage = "https://github.com/elsoul/hotel_price"
14
14
  spec.license = "Apache-2.0"
15
15
  spec.metadata = { "source_code_uri" => "https://github.com/elsoul/hotel_price" }
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require "json"
2
2
 
3
3
  module HotelPrice::Agoda
4
4
  class AgodaAPI
@@ -20,20 +20,20 @@ module HotelPrice::Agoda
20
20
  checkout_arg = (t + 1).strftime("%Y-%m-%d")
21
21
 
22
22
  params = {
23
- "criteria": {
24
- "additional": {
25
- "currency": "JPY",
26
- "discountOnly": false,
27
- "language": "ja-jp",
28
- "occupancy": {
29
- "numberOfAdult": num_adults,
30
- "numberOfChildren": 0
31
- }
32
- },
33
- "checkInDate": checkin_arg,
34
- "checkOutDate": checkout_arg,
35
- "hotelId": [hotel_id]
36
- }
23
+ "criteria": {
24
+ "additional": {
25
+ "currency": "JPY",
26
+ "discountOnly": false,
27
+ "language": "ja-jp",
28
+ "occupancy": {
29
+ "numberOfAdult": num_adults,
30
+ "numberOfChildren": 0
31
+ }
32
+ },
33
+ "checkInDate": checkin_arg,
34
+ "checkOutDate": checkout_arg,
35
+ "hotelId": [hotel_id]
36
+ }
37
37
  }
38
38
 
39
39
  url = URI.parse(endpoint_url)
@@ -46,10 +46,10 @@ module HotelPrice::Agoda
46
46
  end
47
47
 
48
48
  parsed_body = JSON.parse(res.body)
49
- if parsed_body['results'].nil? || parsed_body['results'].empty?
49
+ if parsed_body["results"].nil? || parsed_body["results"].empty?
50
50
  return "No rooms for search criteria - please confirm hotel ID"
51
51
  end
52
- parsed_body['results'][0]['dailyRate']
52
+ parsed_body["results"][0]["dailyRate"]
53
53
  end
54
54
  end
55
55
  end
@@ -9,7 +9,7 @@ module HotelPrice::Agoda
9
9
  end
10
10
 
11
11
  def get_price(agoda_hotel_id, checkin_date, num_adults)
12
- date = DateTime.now.strftime("%Y-%m-%d")
12
+ date = Time.now.strftime("%Y-%m-%d")
13
13
 
14
14
  query_string = make_query_string(checkin_date.to_s, num_adults)
15
15
  url = "https://www.agoda.com/ja-jp/#{agoda_hotel_id}.html?#{query_string}"
@@ -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,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,7 +1,4 @@
1
1
  module HotelPrice::Rakuten
2
- ## mode 0 - headless
3
- ## mode 1 - docker selenium
4
- ## mode 2 - debug
5
2
  class RakutenScraper
6
3
  @mode
7
4
 
@@ -10,7 +7,7 @@ module HotelPrice::Rakuten
10
7
  end
11
8
 
12
9
  def get_price(rakuten_hotel_id, checkin_date, num_adults)
13
- date = DateTime.now.strftime("%Y-%m-%d")
10
+ date = Time.now.strftime("%Y-%m-%d")
14
11
 
15
12
  query_string = make_query_string(checkin_date.to_s, num_adults)
16
13
  url = "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}?#{query_string}"
@@ -46,77 +43,5 @@ module HotelPrice::Rakuten
46
43
  return "" if num_adults.to_i <= 1
47
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"
48
45
  end
49
-
50
- def review rakuten_hotel_id
51
- driver = HotelPrice.get_selenium_driver @mode
52
- driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_hotel_id}/review.html")
53
- sleep 2
54
- comment_area = driver.find_elements(:class_name, "commentBox")
55
- data = comment_area.map do |f|
56
- if f.find_element(class_name: "user").text.include?("投稿者さん")
57
- username = f.find_element(class_name: "user").text
58
- generation = 0
59
- gender = ""
60
- else
61
- username = f.find_element(class_name: "user").text.match(/(^.+ )/).to_s.strip
62
- generation = f.find_element(class_name: "user").text.match(/\[.+代/).to_s.gsub("[", "").gsub("代", "")
63
- gender = f.find_element(class_name: "user").text.match(/\/../).to_s.gsub("/", "")
64
- end
65
- {
66
- date: f.find_element(class_name: "time").text.gsub("年", "").gsub("月", "").gsub("日", ""),
67
- rate: f.find_element(class_name: "rate").text,
68
- username: username,
69
- generation: generation,
70
- gender: gender,
71
- rakuten_hotel_id: rakuten_hotel_id,
72
- comment: f.find_element(class_name: "commentSentence").text
73
- }
74
- end
75
- driver.quit
76
- data
77
- end
78
-
79
- def get_photo_num rakuten_hotel_id
80
- driver = HotelPrice.get_selenium_driver @mode
81
- driver.get "https://hotel.travel.rakuten.co.jp/hinfo/#{rakuten_hotel_id}/"
82
- sleep 2
83
- num = driver.find_element(:id, "navPht").text.gsub("写真・動画(", "").gsub(")", "").to_i
84
- driver.quit
85
- num
86
- end
87
-
88
- def get_bf_plan_num rakuten_hotel_id
89
- driver = HotelPrice.get_selenium_driver @mode
90
- driver.get "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}"
91
- driver.find_element(:id, "focus1").click
92
- driver.find_element(:id, "dh-squeezes-submit").click
93
- sleep 3
94
- plan_num = driver.find_elements(:class, "planThumb")
95
- driver.quit
96
- plan_num.size
97
- end
98
-
99
- def get_dayuse_plan_num rakuten_hotel_id
100
- driver = HotelPrice.get_selenium_driver @mode
101
- driver.get "https://hotel.travel.rakuten.co.jp/hotelinfo/dayuse/?f_no=#{rakuten_hotel_id}"
102
- sleep 5
103
- plan_num = driver.find_elements(:class, "planThumb")
104
- driver.quit
105
- plan_num.size
106
- end
107
-
108
- def get_detail_class_code rakuten_hotel_id
109
- driver = HotelPrice.get_selenium_driver @mode
110
- driver.get "https://hotel.travel.rakuten.co.jp/hinfo/?f_no=#{rakuten_hotel_id}"
111
- {
112
- status: "found",
113
- detail_class_code: driver.find_element(id: "breadcrumbs-detail").attribute("href").match(/\/.\./).to_s.gsub("/", "").gsub(".", "")
114
- }
115
- rescue StandardError
116
- {
117
- status: "not_found",
118
- detail_class_code: ""
119
- }
120
- end
121
46
  end
122
47
  end
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.6.1"
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.6.1
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-08-03 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
@@ -109,7 +109,7 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '3.141'
112
- description: 'Empower World Travel Information Technology '
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
@@ -144,11 +144,9 @@ files:
144
144
  - lib/hotel_price/expedia/expedia_scraper.rb
145
145
  - lib/hotel_price/jalan.rb
146
146
  - lib/hotel_price/jalan/jalan_api.rb
147
- - lib/hotel_price/jalan/jalan_console.rb
148
147
  - lib/hotel_price/jalan/jalan_scraper.rb
149
148
  - lib/hotel_price/rakuten.rb
150
149
  - lib/hotel_price/rakuten/rakuten_api.rb
151
- - lib/hotel_price/rakuten/rakuten_console.rb
152
150
  - lib/hotel_price/rakuten/rakuten_scraper.rb
153
151
  - lib/hotel_price/version.rb
154
152
  homepage: https://github.com/elsoul/hotel_price
@@ -176,5 +174,5 @@ requirements: []
176
174
  rubygems_version: 3.1.4
177
175
  signing_key:
178
176
  specification_version: 4
179
- summary: Scraping Library to get world hotel price
177
+ summary: Webcrawler for checking booking price of travel agencies.
180
178
  test_files: []
@@ -1,12 +0,0 @@
1
- module HotelPrice::Jalan
2
- class JalanConsole
3
- def initialize params
4
- @config = {
5
- login_id: params[:login_id],
6
- login_pw: params[:login_pw],
7
- chain: params[:chain] ||= false,
8
- jalan_hotel_id: params[:jalan_hotel_id] ||= 0
9
- }
10
- end
11
- end
12
- end
@@ -1,528 +0,0 @@
1
- module HotelPrice::Rakuten
2
- class RakutenConsole
3
- def initialize params
4
- @config = {
5
- login_id: params[:login_id],
6
- login_pw: params[:login_pw],
7
- chain: params[:chain] ||= false,
8
- rakuten_hotel_id: params[:rakuten_hotel_id] ||= 0,
9
- mode: params[:mode] ||= :chrome
10
- }
11
- @wait = Selenium::WebDriver::Wait.new(timeout: 100)
12
- @driver = HotelPrice.get_selenium_driver @config[:mode]
13
- if @config[:chain]
14
- go_to_management_page_chain
15
- else
16
- go_to_management_page_single
17
- end
18
- end
19
-
20
- def go_to_management_page_chain
21
- @driver.get "https://manage.travel.rakuten.co.jp/portal/inn/ry_group.main"
22
- @driver.find_element(:name, "f_id").send_keys @config[:login_id].to_s
23
- @driver.find_element(:name, "f_pass").send_keys @config[:login_pw].to_s
24
- @driver.find_element(:xpath, "/html/body/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/form/table/tbody/tr[2]/td[3]/input").click
25
- begin
26
- @driver.find_element(:xpath, "/html/body/center/table/tbody/tr[5]/td[2]/form[3]/input[8]").click
27
- rescue StandardError
28
- @driver.find_element(:xpath, "/html/body/center/table/tbody/tr[7]/td[2]/form[3]/input[8]").click
29
- end
30
- @i = 0
31
- (2..21).each do |i|
32
- rakuten_hotel_id = @driver.find_element(:xpath, "/html/body/center[2]/table/tbody/tr[#{i}]/td[1]").text
33
- @i = i if @config[:rakuten_hotel_id].to_s == rakuten_hotel_id.to_s
34
- break if @i == i
35
- end
36
- until @i != 0
37
- @driver.find_element(:xpath, "/html/body/table/tbody/tr/td[2]/form/input[10]").click
38
- (2..21).each do |i|
39
- rakuten_hotel_id = @driver.find_element(:xpath, "/html/body/center[2]/table/tbody/tr[#{i}]/td[1]").text
40
- @i = i if @config[:rakuten_hotel_id].to_s == rakuten_hotel_id.to_s
41
- break if @i == i
42
- end
43
- end
44
- @driver.find_element(:xpath, "/html/body/center[2]/table/tbody/tr[#{@i}]/td[3]/form/input[10]").click
45
- @driver
46
- end
47
-
48
- def go_to_management_page_single
49
- @driver.get "https://manage.travel.rakuten.co.jp/portal/inn/mp_kanri_image_up.main"
50
- @driver.find_element(:name, "f_id").send_keys @config[:login_id]
51
- @driver.find_element(:name, "f_pass").send_keys @config[:login_pw]
52
- @driver.find_element(:xpath, "/html/body/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/form/table/tbody/tr[2]/td[3]/input").click
53
- @driver
54
- end
55
-
56
- def go_to_plan_setting
57
- @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[3]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/input").click
58
- @wait.until { @driver.find_element(:link_text, "宿泊プラン") }
59
- @driver.find_element(:link_text, "宿泊プラン").click
60
- @plans = @driver.find_elements(:class, "h_top_pl_name")
61
- @driver
62
- end
63
-
64
- def get_plan_num
65
- go_to_plan_setting
66
- @driver.quit
67
- @plans.size
68
- end
69
-
70
- def save_plan_name
71
- go_to_plan_setting
72
- @data = {}
73
- @plans.each_with_index do |row, i|
74
- cells = row.find_elements(:css, "td")
75
- plan_info = row.text.split(":")
76
- @data[i] = {
77
- hotel_id: @hotel.id,
78
- manage_number: plan_info[0],
79
- plan_name: plan_info[1]
80
- }
81
- puts "saved" if RakutenPlan.create(@data[i]).valid?
82
- end
83
- @driver.quit
84
- end
85
-
86
- def edit_plan
87
- go_to_plan_setting
88
- @data = {}
89
- @plans.each_with_index do |row, i|
90
- cells = row.find_elements(:css, "td")
91
- plan_info = row.text.split(":")
92
- @data[i] = {
93
- hotel_id: @hotel.id,
94
- manage_number: plan_info[0],
95
- plan_name: plan_info[1]
96
- }
97
- end
98
-
99
- (0..@plans.size - 1).each do |i|
100
- plan = RakutenPlan.find_by(manage_number: @data[i][:manage_number])
101
- @driver.find_element(:link_text, @data[i][:plan_name]).click
102
- @driver.find_element(:xpath, "/html/body/form[4]/table[1]/tbody/tr/td/table/tbody[1]/tr[3]/td[2]").text
103
- flag = []
104
- flag[0] = "楽天トラベル[宿泊のみ]" if @driver.find_element(:name, "f_tabi_flg").selected?
105
-
106
- if @driver.find_element(:name, "f_dp_del_flg").selected?
107
- flag[1] = "ANA楽パック" if @driver.find_element(:name, "f_dp_ana_flg").selected?
108
- flag[2] = "JAL楽パック" if @driver.find_element(:name, "f_dp_jal_flg").selected?
109
- end
110
- flag[3] = "R-with" if @driver.find_element(:name, "f_kobetu_flg").selected?
111
- begin
112
- plan_name_p = @driver.find_element(:name, "f_dp_title").attribute("value")
113
- plan_body_p = @driver.find_element(:name, "f_dp_naiyo").attribute("value")
114
-
115
- plan_name_r = @driver.find_element(:name, "f_rw_title").attribute("value")
116
- plan_body_r = @driver.find_element(:name, "f_rw_naiyo").attribute("value")
117
- rescue StandardError => e
118
- plan_name_p = ""
119
- plan_body_p = ""
120
-
121
- plan_name_r = ""
122
- plan_body_r = ""
123
- puts "no dp"
124
- puts e
125
- end
126
-
127
- plan_body = @driver.find_element(:name, "f_naiyo").attribute("value")
128
-
129
- # inbound = @driver.find_element(:xpath, "/html/body/form[4]/table[1]/tbody/tr/td/table/tbody[1]/tr[11]/td[2]/table/tbody/tr[1]/td/label") if @driver.find_element(:name, "f_multi").selected?
130
- @room_types = @driver.find_elements(:name, "f_syu")
131
- @room_type = []
132
- @room_types.each_with_index do |row, i|
133
- if row.selected?
134
- @room_type[i - 1] = row.attribute("value")
135
- end
136
- end
137
- plan_start_y = @driver.find_element(:name, "f_k_nen1").attribute("value")
138
- plan_start_m = @driver.find_element(:name, "f_k_tuki1").attribute("value")
139
- plan_start_d = @driver.find_element(:name, "f_k_hi1").attribute("value")
140
- plan_end_y = @driver.find_element(:name, "f_k_nen2").attribute("value")
141
- plan_end_m = @driver.find_element(:name, "f_k_tuki2").attribute("value")
142
- plan_end_d = @driver.find_element(:name, "f_k_hi2").attribute("value")
143
- stay_start_y = @driver.find_element(:name, "f_nen1").attribute("value")
144
- stay_start_m = @driver.find_element(:name, "f_tuki1").attribute("value")
145
- stay_start_d = @driver.find_element(:name, "f_hi1").attribute("value")
146
- stay_end_y = @driver.find_element(:name, "f_nen2").attribute("value")
147
- stay_end_m = @driver.find_element(:name, "f_tuki2").attribute("value")
148
- stay_end_d = @driver.find_element(:name, "f_hi2").attribute("value")
149
- min_stay = @driver.find_element(:name, "f_min_hak").attribute("value")
150
- max_stay = @driver.find_element(:name, "f_max_hak").attribute("value")
151
- checkintime = @driver.find_element(:name, "f_lt_plan_in").attribute("value")
152
- checkouttime = @driver.find_element(:name, "f_lt_plan_in_limit").attribute("value")
153
-
154
- @driver.find_elements(:name, "f_credit").each_with_index do |f, i|
155
- next unless f.selected?
156
-
157
- @payment_method = if i == 0
158
- "現金決済または事前カード決済"
159
- elsif i == 1
160
- "事前カード決済のみ"
161
- elsif i == 2
162
- "現金のみ"
163
- else
164
- ""
165
- end
166
- end
167
-
168
- plan_hash = {
169
- plan_name_p: plan_name_p,
170
- plan_name_r: plan_name_r,
171
- plan_body: plan_body.gsub("\n", ""),
172
- plan_body_p: plan_body_p.gsub("\n", ""),
173
- plan_body_r: plan_body_r.gsub("\n", ""),
174
- # :inbound => inbound,
175
- room_type_ids: @room_type,
176
- plan_start: plan_start_y + "-" + plan_start_m + "-" + plan_start_d,
177
- plan_end: plan_end_y + "-" + plan_end_m + "-" + plan_end_d,
178
- stay_start: stay_start_y + "-" + stay_start_m + "-" + stay_start_d,
179
- stay_end: stay_end_y + "-" + stay_end_m + "-" + stay_end_d,
180
- payment_method: @payment_method,
181
- min_stay: min_stay,
182
- max_stay: max_stay,
183
- checkintime: checkintime,
184
- checkouttime: checkouttime
185
- }
186
- puts "plan saved!: #{plan_hash}" if plan.update_attributes(plan_hash)
187
- @driver.navigate.back
188
- end
189
-
190
- @driver.quit
191
- end
192
-
193
- def save_room_type
194
- @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[3]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/input").click
195
- @wait.until { @driver.find_element(:link_text, "宿泊") }
196
- @driver.find_element(:link_text, "宿泊").click
197
- @room_types = @driver.find_elements(:class, "h_top_rm_name")
198
- @data = {}
199
- @room_types.each_with_index do |row, i|
200
- cells = row.find_elements(:css, "td")
201
- room_type_info = row.text.split(":")
202
- @data[i] = {
203
- hotel_id: @hotel.id,
204
- room_type_id: room_type_info[0],
205
- room_type_name: room_type_info[1]
206
- }
207
- puts "saved" if RakutenRoom.create(@data[i]).valid?
208
- end
209
- @driver.quit
210
- end
211
-
212
- def edit_room_type
213
- @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[3]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/input").click
214
- @wait.until { @driver.find_element(:link_text, "宿泊") }
215
- @driver.find_element(:link_text, "宿泊").click
216
- @room_types = @driver.find_elements(:class, "h_top_rm_name")
217
- @data = {}
218
- @room_types.each_with_index do |row, i|
219
- cells = row.find_elements(:css, "td")
220
- room_type_info = row.text.split(":")
221
- @data[i] = {
222
- hotel_id: @hotel.id,
223
- room_type_id: room_type_info[0],
224
- room_type_name: room_type_info[1]
225
- }
226
- end
227
- (0..@data.size - 1).each do |room_types|
228
- @driver.find_element(:link_text, @data[room_types][:room_type_name]).click
229
- flag = []
230
- flag[0] = "楽天トラベル[宿泊のみ]" if @driver.find_element(:name, "f_tabimado_del_flg").selected?
231
-
232
- if @driver.find_element(:name, "f_dp_del_flg").selected?
233
- flag[1] = "楽天トラベルパッケージ"
234
- room_type_name_p = @driver.find_element(:name, "f_n_dp_syu").attribute("value")
235
- remark_p = @driver.find_element(:name, "f_r_dp_syu").attribute("value")
236
- else
237
- room_type_name_p = ""
238
- remark_p = ""
239
- end
240
- flag[2] = "R-with" if @driver.find_element(:name, "f_kobetu_del_flg").selected?
241
- flag[3] = "R-with[割引料金]" if @driver.find_element(:name, "f_vip_del_flg").selected?
242
-
243
- room_facility = []
244
- room_facility[0] = "トイレ" if @driver.find_element(:id, "view4_toilet") .selected?
245
- room_facility[1] = "バス" if @driver.find_element(:id, "view4_bath") .selected?
246
- room_facility[2] = "シャワーのみ" if @driver.find_element(:id, "view4_shower") .selected?
247
- img_url = @driver.find_element(:name, "f_img_url").attribute("value")
248
- @driver.find_elements(:name, "f_pic_flg").each do |f|
249
- img_url = if f.selected?
250
- @driver.find_element(:name, "f_img_url").attribute("value")
251
- else
252
- ""
253
- end
254
- end
255
-
256
- @driver.find_elements(:name, "f_credit").each_with_index do |f, i|
257
- next unless f.selected?
258
-
259
- @payment_method = if i == 0
260
- "現金決済または事前カード決済"
261
- elsif i == 1
262
- "事前カード決済のみ"
263
- elsif i == 2
264
- "現金のみ"
265
- else
266
- ""
267
- end
268
- end
269
-
270
- if @driver.find_element(:id, "nc_width1").selected?
271
- mm = @driver.find_element(:id, "su_width1").attribute("value")
272
- room_size = mm.to_s + "㎡"
273
- room_size_mm = mm.to_i
274
- room_size_tatami = ""
275
- elsif @driver.find_element(:id, "nc_width2").selected?
276
- mm = @driver.find_element(:id, "nc_width2").attribute("value")
277
- room_size = mm.to_s + "畳"
278
- room_size_mm = ""
279
- room_size_tatami = mm.to_i
280
- elsif @driver.find_element(:id, "nc_width3").selected?
281
- room_size = "客室により異なる"
282
- room_size_mm = ""
283
- room_size_tatami = ""
284
- end
285
- (0..5).each do |i|
286
- @driver.find_element(:id, "view2_type_#{i}").attribute("value") if @driver.find_element(:id, "view2_type_#{i}").selected?
287
- end
288
-
289
- # Pause sort
290
- # room_facility = %w(禁煙ルーム 喫煙ルーム インターネットができる部屋 露天風呂付き客室 ジャグジーのある客室 離れ客室 コーナールーム 二間以上 洗浄機付きトイレ 高層階 夜景が見える 海が見える 山が見える 湖が見える 川が見える)
291
- # sort = []
292
- # for i in 1 .. 13
293
- # sort[i-1] = room_facility[i-1] if @driver.find_element(:id, "narrow#{i}").selected?
294
- # end
295
- # sort.compact!
296
-
297
- room_db = RakutenRoom.find_by(hotel_id: @hotel.id, room_type_id: @data[room_types][:room_type_id])
298
- room_type_data = {
299
- public: flag,
300
- room_type_name_p: room_type_name_p,
301
- capacity_min: @driver.find_element(:xpath, "/html/body/table[8]/tbody/tr/td/table[1]/tbody/tr[5]/td[2]").text.gsub(" 名~ 名", ""),
302
- capacity_max: @driver.find_element(:name, "f_max").attribute("value"),
303
- remark: @driver.find_element(:name, "f_bikou").attribute("value"),
304
- remark_p: remark_p,
305
- room_size: room_size,
306
- room_size_mm: room_size_mm,
307
- room_size_tatami: room_size_tatami,
308
- room_category: room_category,
309
- room_facility: room_facility,
310
- room_img: img_url,
311
- #:sort => sort,
312
- payment_method: @payment_method
313
- }
314
- puts "room type info updated: #{@hotel.id}" if room_db.update_attributes(room_type_data)
315
- @driver.navigate.back
316
- end
317
- @driver.quit
318
- end
319
-
320
- def login_check
321
- exp = @driver.find_element(:xpath, "/html/body/table[1]/tbody/tr[1]/td/table/tbody/tr/td[5]/table/tbody/tr[1]/td").text.gsub("次回パスワード更新日:", "").gsub("※事前にパスワードを変更されたい場合はこちらをご参照ください。\n", "")
322
- rakuten_hotel_id = @driver.find_element(:xpath, "/html/body/table[1]/tbody/tr[1]/td/table/tbody/tr/td[2]/table/tbody/tr/td").text.gsub("施設番号 : ", "").split("\n")[0]
323
- {
324
- status: "success",
325
- password_exp_date: exp,
326
- rakuten_hotel_id: rakuten_hotel_id
327
- }
328
- rescue StandardError => e
329
- {
330
- status: "error",
331
- error: e.to_s
332
- }
333
- end
334
-
335
- # def get_area_seo_rank
336
- # @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[1]/tbody/tr[2]/td/table/tbody/tr[1]/td[5]/table/tbody/tr/td/table[1]/tbody/tr[5]/td[2]/font/b")
337
- # rows = @driver.find_elements(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[1]/tbody/tr[2]/td/table/tbody/tr[1]/td[5]/table/tbody/tr/td/table[1]/tbody/tr[5]")
338
- # rows.each do |f|
339
- # cells = f.find_elements(:css, "td").map(&:text)
340
- # return cells[1]
341
- # end
342
- # end
343
-
344
- def degit2 num
345
- num = "0#{num}" if num.to_s.size == 1
346
- num
347
- end
348
-
349
- def get_reservation_info
350
- t = Time.now
351
- @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[3]/tbody/tr[2]/td[2]/table/tbody/tr[3]/td/input").click
352
- if t.day == 1
353
- last_month = degit2 t.prev_month.month.to_i
354
- yesterday = degit2 t.prev_month.end_of_month.day.to_i
355
- this_month = degit2 t.month.to_i
356
- today = degit2 t.day.to_i
357
- last_month_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_tuki1"))
358
- last_month_select.select_by(:value, last_month.to_s)
359
- yesterday_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_hi1"))
360
- yesterday_select.select_by(:value, yesterday.to_s)
361
- this_month_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_tuki2"))
362
- this_month_select.select_by(:value, this_month.to_s)
363
- today_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_hi2"))
364
- today_select.select_by(:value, today.to_s)
365
- search = @driver.find_element(:xpath, "/html/body/table[7]/tbody/tr[1]/td[4]/input").click
366
- else
367
- yesterday = degit2 t.yesterday.day.to_i
368
- today = degit2 t.day.to_i
369
- yesterday_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_hi1"))
370
- yesterday_select.select_by(:value, yesterday.to_s)
371
- today_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_hi2"))
372
- today_select.select_by(:value, today.to_s)
373
- search = @driver.find_element(:xpath, "/html/body/table[7]/tbody/tr[1]/td[4]/input").click
374
- end
375
-
376
- @wait.until { @driver.find_elements(:xpath, "//tr") }
377
- sleep 10
378
- rows = @driver.find_elements(:xpath, "//tr")
379
- row_num = rows.size
380
- if row_num != 25
381
- rows[21..row_num - 4].each do |row|
382
- cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
383
- point = cells[4].split("\n")[3].gsub("予定ポイント:", "").gsub(" ポイント", "") if cells[4].split("\n")[3].present?
384
- begin
385
- if cells[0].size < 7
386
- @reservation_date = {
387
- date: Time.now.strftime("%F"),
388
- reservation_status: cells[0],
389
- reservation_date: cells[1].split("\n")[2],
390
- checkindate: cells[1].split("\n")[0],
391
- checkoutdate: cells[1].split("\n")[1],
392
- room_type: cells[2].split("\n")[0],
393
- reservation_number: cells[2].split("\n")[2].split(":")[1],
394
- payment_on_cash: cells[3].gsub("円", "").to_i,
395
- price: cells[2].split("\n")[1].split(":")[0].gsub("円人数", ""),
396
- guest_name: cells[4].split("\n")[0],
397
- guest_tel: cells[4].split("\n")[1].gsub("(", "").gsub(")", ""),
398
- point: point
399
- }
400
- else
401
- plan_number = cells[2].split("\n")[0].scan(/\(.+?\)/).last
402
- @reservation_date = {
403
- date: Time.now.strftime("%F"),
404
- hotel_id: @hotel.id,
405
- reservation_status: cells[0].split("\n\n")[1],
406
- reservation_date: cells[1].split("\n")[2],
407
- checkindate: cells[1].split("\n")[0],
408
- checkoutdate: cells[1].split("\n")[1],
409
- plan_name: cells[2].split("\n")[0],
410
- plan_number: plan_number.to_s.gsub("(", "").gsub(")", ""),
411
- room_type: cells[2].split("\n")[1],
412
- price: cells[2].split("\n")[2].split(":")[0].gsub("円人数", ""),
413
- ppl_num: cells[2].split("\n")[2].split(":")[1].gsub("(", "").gsub(")", ""),
414
- reservation_number: cells[2].split("\n")[3].gsub("予約番号:", ""),
415
- payment_on_cash: cells[3].gsub("円", "").to_i,
416
- member_name: cells[4].split("\n")[0],
417
- guest_name: cells[4].split("\n")[1],
418
- guest_tel: cells[4].split("\n")[2].gsub("(", "").gsub(")", ""),
419
- point: point
420
- }
421
- end
422
- puts "saved:#{@reservation_date}" if RakutenReservation.create(@reservation_date).valid?
423
- rescue StandardError => e
424
- puts e
425
- end
426
- end
427
- end
428
- @driver.quit
429
- end
430
-
431
- # def daily_data_past
432
- # @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[2]/tbody/tr[1]/td[1]/table/tbody/tr/td[3]/a/img").click
433
- # @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[5]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr/td[1]/input").click
434
- # sleep 3
435
- # (0..13).each do |i|
436
- # select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_date"))
437
- # select.select_by(:index, i)
438
- # display_data = @driver.find_element(:xpath, '//input[@value = "表示"]')
439
- # display_data.click
440
- # rows = @driver.find_elements(:xpath, "//tr")
441
- # rows[27..58].map do |row|
442
- # cells = row.find_elements(:css, "td[align=RIGHT]").map { |a| a.text.strip.gsub(",", "") }
443
- # break unless cells[5] && cells[5].to_i > 1
444
- # {
445
- # date: cells[0],
446
- # reservation_sales: cells[1],
447
- # access_ppl: cells[2],
448
- # cvr: cells[3],
449
- # reservation_unit_price: cells[4],
450
- # pv: cells[5],
451
- # pc_retained: cells[6],
452
- # pc_deliveries: cells[7],
453
- # pc_total_delivered: cells[8],
454
- # sp_retained: cells[9],
455
- # sp_deliveries: cells[10],
456
- # sp_total_delivered: cells[11]
457
- # }
458
- # end
459
- # end
460
- # end
461
-
462
- def daily_data
463
- @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[2]/tbody/tr[1]/td[1]/table/tbody/tr/td[3]/a/img").click
464
- @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[5]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr/td[1]/input").click
465
- sleep 3
466
- if Time.now.day == 1
467
- else
468
- value = if Time.now.month.to_s.size == 2
469
- Time.now.year.to_s + Time.now.month.to_s + "01"
470
- else
471
- Time.now.year.to_s + "0" + Time.now.month.to_s + "01"
472
- end
473
- select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_date"))
474
- select.select_by(:value, value)
475
- end
476
- @driver.find_element(:xpath, '//input[@value = "表示"]').click
477
- rows = @driver.find_elements(:xpath, "//tr")
478
- data = []
479
- rows[27..58].each do |row|
480
- cells = row.find_elements(:css, "td[align=RIGHT]").map { |a| a.text.strip.gsub(",", "") }
481
- break unless cells[5] && cells[5].to_i > 1
482
- data << {
483
- date: cells[0],
484
- reservation_sales: cells[1],
485
- access_ppl: cells[2],
486
- cvr: cells[3],
487
- reservation_unit_price: cells[4],
488
- pv: cells[5],
489
- pc_retained: cells[6],
490
- pc_deliveries: cells[7],
491
- pc_total_delivered: cells[8],
492
- sp_retained: cells[9],
493
- sp_deliveries: cells[10],
494
- sp_total_delivered: cells[11]
495
- }
496
- end
497
- data
498
- end
499
-
500
- def monthly_data_past
501
- @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[2]/tbody/tr[1]/td[1]/table/tbody/tr/td[3]/a/img").click
502
- @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[5]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr/td[2]/input").click
503
- @driver.find_element(:xpath, "/html/body/center/table[1]/tbody/tr[2]/td/table/tbody/tr[2]/td/form/input[8]").click
504
- rows = @driver.find_elements(:xpath, "//tr")
505
- rows[19..31].map do |row|
506
- cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
507
- break unless cells[9] && cells[9].to_i > 1
508
- {
509
- date: cells[0].gsub("/", "").to_s + "01",
510
- reservation_sales: cells[1],
511
- reservation_ppl: cells[2],
512
- access_ppl: cells[3],
513
- access_ppl_top_avg: cells[4],
514
- cvr: cells[5],
515
- cvr_top_avg: cells[6],
516
- reservation_unit_price: cells[7],
517
- reservation_unit_price_top_avg: cells[8],
518
- pv: cells[9],
519
- pv_top_avg: cells[10],
520
- rmail_list_num: cells[11],
521
- rmail_num: cells[12],
522
- rmail_delivery_num: cells[13],
523
- prize: cells[14]
524
- }
525
- end
526
- end
527
- end
528
- end