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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rubocop.yml +68 -104
- data/Gemfile.lock +15 -15
- data/LICENSE.txt +67 -21
- data/README.md +127 -21
- data/hotel_price.gemspec +12 -11
- data/lib/hotel_price.rb +10 -6
- data/lib/hotel_price/agoda/agoda_api.rb +17 -17
- data/lib/hotel_price/agoda/agoda_scraper.rb +12 -6
- data/lib/hotel_price/booking/booking_scraper.rb +11 -6
- data/lib/hotel_price/expedia/expedia_scraper.rb +11 -5
- data/lib/hotel_price/jalan.rb +0 -1
- data/lib/hotel_price/jalan/jalan_api.rb +1 -1
- data/lib/hotel_price/jalan/jalan_scraper.rb +13 -6
- data/lib/hotel_price/rakuten.rb +0 -1
- data/lib/hotel_price/rakuten/rakuten_api.rb +1 -114
- data/lib/hotel_price/rakuten/rakuten_scraper.rb +12 -84
- data/lib/hotel_price/version.rb +1 -1
- metadata +24 -27
- data/.DS_Store +0 -0
- data/lib/hotel_price/jalan/jalan_console.rb +0 -12
- data/lib/hotel_price/rakuten/rakuten_console.rb +0 -528
data/.DS_Store
DELETED
Binary file
|
@@ -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] ||= 0
|
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
|