hotel_price 0.3.0 → 0.3.1

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: 389771a28d381cf3ed84dff2cb45ac0b9e50a5d31e18d7020b2b9495a88c6421
4
- data.tar.gz: c6844cdbf8353d7ee34128ed8e633a404aee7d9c85d7a30371ef580ec0e9da04
3
+ metadata.gz: a258d3e3cd27cf75ec732a05891c6cc464603e505e897c4160654c389851b08b
4
+ data.tar.gz: 0111e2c99abd43c92e440b0ee798f4c9633ae5887c87e97e6d700b8613ee8ad9
5
5
  SHA512:
6
- metadata.gz: f623764224c7824f78ad0be9ec170cce50760624b4da5b77ce56d1c7115b007c51ab7f74e148567ce035b31829b46a5965780534ce1a08b7da5f5f336a0dfdfa
7
- data.tar.gz: 8027c10a811a55a36ecafb4a81e92e91143cb28e50cb6f2a71516ca34d7ecb5cf770119f0889089f620422538b6a0c74efd873c5707a85c7790c2e9af3388e85
6
+ metadata.gz: af2482c3ee4b4eadb3d101d4f075ca76d241600ee1c7652495d1bd53fc6954589923a371d09c97855d00794f87126bd797b780ff5e6731ca82dcca670a83d89a
7
+ data.tar.gz: 8239b9ce0695efa32ac9cb0dbc58e664d03411f6f419bf6cd485b539dc910a7667706e1165a40660b9771b617b7eec6346bc6b0346694804c8f7d05c6f77d30f
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in hotel_price.gemspec
4
4
  gemspec
5
- gem "selenium-webdriver", "~> 3.141"
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.2.8)
4
+ hotel_price (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  childprocess (3.0.0)
10
10
  diff-lcs (1.3)
11
- rake (10.5.0)
11
+ rake (13.0.1)
12
12
  rspec (3.9.0)
13
13
  rspec-core (~> 3.9.0)
14
14
  rspec-expectations (~> 3.9.0)
@@ -33,7 +33,7 @@ PLATFORMS
33
33
  DEPENDENCIES
34
34
  bundler (~> 2.0)
35
35
  hotel_price!
36
- rake (~> 10.0)
36
+ rake (>= 12.3.3)
37
37
  rspec (~> 3.0)
38
38
  selenium-webdriver (~> 3.141)
39
39
 
data/hotel_price.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_development_dependency "bundler", "~> 2.0"
32
- spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rake", ">= 12.3.3"
33
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
34
  spec.add_development_dependency "selenium-webdriver", "~> 3.141"
35
35
  end
data/lib/hotel_price.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require "hotel_price/version"
2
2
  require "hotel_price/rakuten"
3
3
  require "hotel_price/jalan"
4
+ require "hotel_price/agoda"
5
+ require "hotel_price/booking"
4
6
  require "selenium-webdriver"
5
7
  require "net/http"
6
8
 
@@ -0,0 +1,6 @@
1
+ require_relative "./agoda/agoda_api"
2
+
3
+ module HotelPrice
4
+ module Agoda
5
+ end
6
+ end
@@ -0,0 +1,48 @@
1
+ module HotelPrice::Agoda
2
+ class AgodaAPI
3
+ def initialize api_key
4
+ @api_key = api_key
5
+ end
6
+ def test
7
+ endpoint_url = "http://affiliateapi7643.agoda.com/affiliateservice/lt_v1"
8
+ # 検索条件の指定
9
+ # cityId, checkInDate, checkOutDate は必須、ソレ以外はオプション。
10
+ params = {
11
+ "criteria": {
12
+ "additional": {
13
+ "currency": "JPY",
14
+ "dailyRate": {
15
+ "maximum": 100000,
16
+ "minimum": 1000
17
+ },
18
+ "discountOnly": false,
19
+ "language": "ja-jp",
20
+ "maxResult": 10,
21
+ "minimumReviewScore": 0,
22
+ "minimumStarRating": 0,
23
+ "occupancy": {
24
+ "numberOfAdult": 1,
25
+ "numberOfChildren": 0
26
+ },
27
+ "sortBy": "PriceAsc"
28
+ },
29
+ "discountOnly": true,
30
+ "checkInDate": "2020-10-02",
31
+ "checkOutDate": "2020-10-03",
32
+ "cityId": 5235
33
+ }
34
+ }
35
+
36
+ url = URI.parse(endpoint_url)
37
+ req = Net::HTTP::Post.new(url.path)
38
+ req["Authorization"] = @api_key
39
+ req["Content-Type"] = "application/json"
40
+ req.body = params.to_json
41
+ res = Net::HTTP.new(url.host, url.port).start do |http|
42
+ http.request(req)
43
+ end
44
+
45
+ puts res.body
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "./booking/booking_scraper"
2
+
3
+ module HotelPrice
4
+ module Booking
5
+ end
6
+ end
@@ -0,0 +1,49 @@
1
+ require "date"
2
+
3
+ module HotelPrice::Booking
4
+ class BookingScraper
5
+ def self.get_price(booking_hotel_id, checkin_date, num_adults)
6
+ date = DateTime.now.strftime("%Y-%m-%d")
7
+
8
+ query_string = make_query_string(checkin_date, num_adults)
9
+ url = "https://www.booking.com/hotel/jp/#{booking_hotel_id}.ja.html?#{query_string}"
10
+ driver = self.get_selenium_driver
11
+ driver.get(url)
12
+ puts url
13
+ sleep 2
14
+
15
+ data = driver.find_elements(:class_name, "hprt-table")
16
+ return { date: date, min_price: 0 } if data.empty?
17
+ price_box = data.first.find_elements(:class_name, "bui-price-display__value")
18
+ return { date: date, min_price: 0 } if price_box.empty?
19
+ price = price_box.first.text.delete("^0-9").to_i
20
+
21
+ { date: date, price: price }
22
+ end
23
+
24
+ def self.make_query_string(checkin_date, num_adults)
25
+ cd_args = make_date_args checkin_date
26
+ na_args = make_num_adults_arg num_adults
27
+ "#{cd_args}&#{na_args}&dist=0&do_availability_check=1&hp_avform=1&hp_group_set=0&no_rooms=1&origin=hp&sb_price_type=total&src=hotel&tab=1&type=total&lang=ja&selected_currency=JPY"
28
+ end
29
+
30
+ def self.make_date_args checkin_date
31
+ Date.parse checkin_date rescue return ""
32
+ t = Date.parse(checkin_date)
33
+ checkin_arg = t.strftime("checkin_monthday=%d&checkin_year_month=%Y-%m")
34
+ checkout_arg = (t + 1).strftime("checkout_monthday=%d&checkout_year_month=%Y-%m")
35
+ "#{checkin_arg}&#{checkout_arg}"
36
+ end
37
+
38
+ def self.make_num_adults_arg num_adults
39
+ return "" if num_adults.to_i <= 1
40
+ "group_adults=#{num_adults}&group_children=0"
41
+ end
42
+
43
+ def self.get_selenium_driver
44
+ options = Selenium::WebDriver::Firefox::Options.new
45
+ options.add_argument("-headless")
46
+ Selenium::WebDriver.for :firefox, options: options
47
+ end
48
+ end
49
+ end
@@ -15,21 +15,12 @@ module HotelPrice::Jalan
15
15
  if doc.css("NumberOfResults").text == "0"
16
16
  {
17
17
  date: DateTime.now.strftime("%Y-%m-%d"),
18
- branch_id: request_body[:branch_id],
19
- stay_date: request_body[:checkindate],
20
- adult_num: request_body[:adult_num],
21
- jalan_hotel_id: request_body[:jalan_hotel_id],
22
18
  plan_num: 0,
23
19
  min_price: 0
24
20
  }
25
21
  else
26
22
  {
27
23
  date: DateTime.now.strftime("%Y-%m-%d"),
28
- branch_id: request_body[:branch_id],
29
- channel: "jalan",
30
- stay_date: request_body[:checkindate],
31
- adult_num: request_body[:adult_num],
32
- jalan_hotel_id: request_body[:jalan_hotel_id],
33
24
  hotel_name: doc.css("Plan").css("Hotel HotelName").text,
34
25
  room_name: doc.css("Plan").css("RoomName").text,
35
26
  plan_name: doc.css("Plan").css("PlanName").text,
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
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.3.0
4
+ version: 0.3.1
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-02-14 00:00:00.000000000 Z
12
+ date: 2020-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -29,16 +29,16 @@ dependencies:
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '10.0'
34
+ version: 12.3.3
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '10.0'
41
+ version: 12.3.3
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +91,10 @@ files:
91
91
  - exe/hotel_price
92
92
  - hotel_price.gemspec
93
93
  - lib/hotel_price.rb
94
+ - lib/hotel_price/agoda.rb
95
+ - lib/hotel_price/agoda/agoda_api.rb
96
+ - lib/hotel_price/booking.rb
97
+ - lib/hotel_price/booking/booking_scraper.rb
94
98
  - lib/hotel_price/jalan.rb
95
99
  - lib/hotel_price/jalan/jalan_api.rb
96
100
  - lib/hotel_price/jalan/jalan_console.rb