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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a89f55a297a504a6e9dc86a123dd336b5e762618f574a6b24749cfcfe394df00
4
- data.tar.gz: 71eb4e9956b772b38316bc6ccf733146879417088cb28cc6f9ffde6984d0bc5c
3
+ metadata.gz: 0a82631788a305757b3d0bffbe8298a441fba18511d678a80c20a2e045f9d408
4
+ data.tar.gz: 8eadeb31ec3d5f4e2dc179f51e15cf3bd2955b5a5afdf8c427ab68f565880833
5
5
  SHA512:
6
- metadata.gz: 56468f07606b0c207a96520a41ce403f45318ea0210482052993d0fd740a9008db83a7a0fb2eaa6f65ef53fd5b9c251fa1e01283313a29b03a5c255116c73b5f
7
- data.tar.gz: dfa6d6f5f2f789ff86819a4b5e2d42dd303f79d090f302d8dcd698c2279566a5d5a13d209bcd972bab1f71263f23f079ae5c8483d440204dee5ac3c403a5d715
6
+ metadata.gz: 1f1cf23d50086583c2096adefcd7a207cad65e775a5810c8e89ea0690a4a4995cff6dd8c0d2fe88dd59569f5768b1271c9cbe5ad09aa6348c6173dc51ee0b29a
7
+ data.tar.gz: d254d83f23aabb34bc1164b8d263cecc13d2fc26d7b4ca4a63401399245304f05c786384ed18eda81e3bb84621386e930c4d59b4442aab7dd9068d9383057346
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.5.2)
4
+ hotel_price (0.5.3)
5
5
  activesupport (~> 6.0.2.1)
6
6
  json (~> 2.3.0)
7
7
  nokogiri (~> 1.10.9)
data/README.md CHANGED
@@ -26,11 +26,14 @@ Or install it yourself as:
26
26
  ### Rakuten Travel
27
27
 
28
28
  #### Rakuten API
29
- Set `rakuten_hotel_id`
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::RakutenTravel::RakutenAPI.new(
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
- @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
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
- @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].each 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
- @output_hash = {
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
- puts "saved in DB:#{@output_hash}" if RakutenDaily.create(@output_hash).valid?
461
- end
462
- end
463
- @driver.quit
464
- rescue StandardError => e
465
- @driver.quit
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
- @output_hash = {
490
- "date" => cells[0],
491
- "hotel_id" => @hotel.id,
492
- "reservation_sales" => cells[1],
493
- "access_ppl" => cells[2],
494
- "cvr" => cells[3],
495
- "reservation_unit_price" => cells[4],
496
- "pv" => cells[5],
497
- "pc_retained" => cells[6],
498
- "pc_deliveries" => cells[7],
499
- "pc_total_delivered" => cells[8],
500
- "sp_retained" => cells[9],
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
- @driver.quit
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].each do |row|
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
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
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.3
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-10 00:00:00.000000000 Z
12
+ date: 2020-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler