hotel_price 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +15 -3
- data/lib/hotel_price/rakuten/rakuten_api.rb +1 -12
- data/lib/hotel_price/rakuten/rakuten_console.rb +59 -73
- data/lib/hotel_price/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a82631788a305757b3d0bffbe8298a441fba18511d678a80c20a2e045f9d408
|
4
|
+
data.tar.gz: 8eadeb31ec3d5f4e2dc179f51e15cf3bd2955b5a5afdf8c427ab68f565880833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f1cf23d50086583c2096adefcd7a207cad65e775a5810c8e89ea0690a4a4995cff6dd8c0d2fe88dd59569f5768b1271c9cbe5ad09aa6348c6173dc51ee0b29a
|
7
|
+
data.tar.gz: d254d83f23aabb34bc1164b8d263cecc13d2fc26d7b4ca4a63401399245304f05c786384ed18eda81e3bb84621386e930c4d59b4442aab7dd9068d9383057346
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,11 +26,14 @@ Or install it yourself as:
|
|
26
26
|
### Rakuten Travel
|
27
27
|
|
28
28
|
#### Rakuten API
|
29
|
-
|
29
|
+
Initialize with `rakuten_hotel_id` and `Rakuten Travel API key`
|
30
|
+
Rakuten Travel API Reference : https://webservice.rakuten.co.jp/api/simplehotelsearch/
|
31
|
+
|
30
32
|
|
31
33
|
```ruby
|
32
|
-
hotel = HotelPrice::
|
33
|
-
rakuten_hotel_id: "128552
|
34
|
+
hotel = HotelPrice::Rakuten::RakutenScraper.new(
|
35
|
+
rakuten_hotel_id: "128552",
|
36
|
+
rakuten_api_key: "api_key"
|
34
37
|
)
|
35
38
|
```
|
36
39
|
|
@@ -40,6 +43,15 @@ Get Hotel Info
|
|
40
43
|
puts hotel.hotel_info
|
41
44
|
```
|
42
45
|
|
46
|
+
|
47
|
+
### RakutenScraper
|
48
|
+
Argments : `rakuten_hotel_id`, `YYYY-MM-DD`, `adult_nums`
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
HotelPrice::Rakuten::RakutenScraper.get_price("128552", (Date.today + 45.day).to_s, 1)
|
52
|
+
```
|
53
|
+
|
54
|
+
|
43
55
|
## Development
|
44
56
|
|
45
57
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -163,16 +163,6 @@ module HotelPrice::Rakuten
|
|
163
163
|
@data_hash
|
164
164
|
end
|
165
165
|
|
166
|
-
def get_area_rank
|
167
|
-
body = get_page_num
|
168
|
-
(1..body[:page_num]).each do |i|
|
169
|
-
body[:page_num] = i
|
170
|
-
rank = search_ranking(body)
|
171
|
-
return rank if rank[:status] == "found"
|
172
|
-
end
|
173
|
-
{ status: "not_found" }
|
174
|
-
end
|
175
|
-
|
176
166
|
def search_ranking params
|
177
167
|
body = {
|
178
168
|
middle_class_code: params[:middle_class_code],
|
@@ -203,8 +193,7 @@ module HotelPrice::Rakuten
|
|
203
193
|
{ status: "not_found" }
|
204
194
|
end
|
205
195
|
|
206
|
-
def get_page_num
|
207
|
-
detail_class_code = HotelPrice::Rakuten::RakutenScraper.get_detail_class_code(@config[:rakuten_hotel_id])[:detail_class_code]
|
196
|
+
def get_page_num detail_class_code
|
208
197
|
hotel = hotel_info
|
209
198
|
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}"
|
210
199
|
uri = URI.parse(url)
|
@@ -334,14 +334,14 @@ module HotelPrice::Rakuten
|
|
334
334
|
}
|
335
335
|
end
|
336
336
|
|
337
|
-
def get_area_seo_rank
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
end
|
337
|
+
# def get_area_seo_rank
|
338
|
+
# @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")
|
339
|
+
# 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]")
|
340
|
+
# rows.each do |f|
|
341
|
+
# cells = f.find_elements(:css, "td").map(&:text)
|
342
|
+
# return cells[1]
|
343
|
+
# end
|
344
|
+
# end
|
345
345
|
|
346
346
|
def degit2 num
|
347
347
|
num = "0#{num}" if num.to_s.size == 1
|
@@ -430,43 +430,39 @@ module HotelPrice::Rakuten
|
|
430
430
|
@driver.quit
|
431
431
|
end
|
432
432
|
|
433
|
-
def daily_data_past
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
puts e.to_json
|
467
|
-
end
|
468
|
-
|
469
|
-
def daily_data_update
|
433
|
+
# def daily_data_past
|
434
|
+
# @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
|
435
|
+
# @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
|
436
|
+
# sleep 3
|
437
|
+
# (0..13).each do |i|
|
438
|
+
# select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_date"))
|
439
|
+
# select.select_by(:index, i)
|
440
|
+
# display_data = @driver.find_element(:xpath, '//input[@value = "表示"]')
|
441
|
+
# display_data.click
|
442
|
+
# rows = @driver.find_elements(:xpath, "//tr")
|
443
|
+
# rows[27..58].map do |row|
|
444
|
+
# cells = row.find_elements(:css, "td[align=RIGHT]").map { |a| a.text.strip.gsub(",", "") }
|
445
|
+
# break unless cells[5] && cells[5].to_i > 1
|
446
|
+
# {
|
447
|
+
# date: cells[0],
|
448
|
+
# reservation_sales: cells[1],
|
449
|
+
# access_ppl: cells[2],
|
450
|
+
# cvr: cells[3],
|
451
|
+
# reservation_unit_price: cells[4],
|
452
|
+
# pv: cells[5],
|
453
|
+
# pc_retained: cells[6],
|
454
|
+
# pc_deliveries: cells[7],
|
455
|
+
# pc_total_delivered: cells[8],
|
456
|
+
# sp_retained: cells[9],
|
457
|
+
# sp_deliveries: cells[10],
|
458
|
+
# sp_total_delivered: cells[11]
|
459
|
+
# }
|
460
|
+
# end
|
461
|
+
# end
|
462
|
+
# end
|
463
|
+
|
464
|
+
def daily_data
|
465
|
+
puts "start"
|
470
466
|
@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
|
471
467
|
@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
|
472
468
|
sleep 3
|
@@ -480,32 +476,29 @@ module HotelPrice::Rakuten
|
|
480
476
|
select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_date"))
|
481
477
|
select.select_by(:value, value)
|
482
478
|
end
|
479
|
+
puts "scraper"
|
483
480
|
@driver.find_element(:xpath, '//input[@value = "表示"]').click
|
484
481
|
rows = @driver.find_elements(:xpath, "//tr")
|
482
|
+
data = []
|
485
483
|
rows[27..58].each do |row|
|
486
484
|
cells = row.find_elements(:css, "td[align=RIGHT]").map { |a| a.text.strip.gsub(",", "") }
|
487
485
|
break unless cells[5] && cells[5].to_i > 1
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
"sp_deliveries" => cells[10],
|
502
|
-
"sp_total_delivered" => cells[11]
|
486
|
+
data << {
|
487
|
+
date: cells[0],
|
488
|
+
reservation_sales: cells[1],
|
489
|
+
access_ppl: cells[2],
|
490
|
+
cvr: cells[3],
|
491
|
+
reservation_unit_price: cells[4],
|
492
|
+
pv: cells[5],
|
493
|
+
pc_retained: cells[6],
|
494
|
+
pc_deliveries: cells[7],
|
495
|
+
pc_total_delivered: cells[8],
|
496
|
+
sp_retained: cells[9],
|
497
|
+
sp_deliveries: cells[10],
|
498
|
+
sp_total_delivered: cells[11]
|
503
499
|
}
|
504
|
-
puts "saved in DB:#{@output_hash}" if RakutenDaily.create(@output_hash).valid?
|
505
500
|
end
|
506
|
-
|
507
|
-
rescue StandardError => e
|
508
|
-
@driver.quit
|
501
|
+
data
|
509
502
|
end
|
510
503
|
|
511
504
|
def monthly_data_past
|
@@ -513,13 +506,11 @@ module HotelPrice::Rakuten
|
|
513
506
|
@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
|
514
507
|
@driver.find_element(:xpath, "/html/body/center/table[1]/tbody/tr[2]/td/table/tbody/tr[2]/td/form/input[8]").click
|
515
508
|
rows = @driver.find_elements(:xpath, "//tr")
|
516
|
-
rows[19..31].
|
509
|
+
rows[19..31].map do |row|
|
517
510
|
cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
|
518
511
|
break unless cells[9] && cells[9].to_i > 1
|
519
|
-
|
520
|
-
data = {
|
512
|
+
{
|
521
513
|
date: cells[0].gsub("/", "").to_s + "01",
|
522
|
-
hotel_id: Branch.find_by_rakuten_hotel_id(@config[:rakuten_hotel_id]).hotel_id,
|
523
514
|
reservation_sales: cells[1],
|
524
515
|
reservation_ppl: cells[2],
|
525
516
|
access_ppl: cells[3],
|
@@ -535,12 +526,7 @@ module HotelPrice::Rakuten
|
|
535
526
|
rmail_delivery_num: cells[13],
|
536
527
|
prize: cells[14]
|
537
528
|
}
|
538
|
-
puts "db saved : #{data}" if RakutenKaruteReservation.create(data).valid?
|
539
529
|
end
|
540
|
-
@driver.quit
|
541
|
-
rescue StandardError => e
|
542
|
-
puts e.to_json
|
543
|
-
@driver.quit
|
544
530
|
end
|
545
531
|
end
|
546
532
|
end
|
data/lib/hotel_price/version.rb
CHANGED
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.
|
4
|
+
version: 0.5.4
|
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-
|
12
|
+
date: 2020-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|