Skip to content

Instantly share code, notes, and snippets.

@olore
Created September 8, 2011 02:32
Show Gist options
  • Save olore/1202460 to your computer and use it in GitHub Desktop.
Save olore/1202460 to your computer and use it in GitHub Desktop.
Find the price of the cheapest room at a "Value Resort" in Disney World
#Specify a "Value" resort to get prices for, or "any" to find the cheapest
resort: Pop Century
#resort: any
#Specify dates to search for. Format: MM/DD/YYYY
dates:
- arrival: 11/29/2011
departure: 12/03/2011
- arrival: 11/30/2011
departure: 12/04/2011
- arrival: 12/01/2011
departure: 12/05/2011
require 'rubygems'
require 'watir-webdriver'
require 'yaml'
def find_reservation_times_for(b, restaurant, date, guests, time)
b.text_field(:id, 'makeResDate').set(date)
b.select_list(:id => "makeResTime").select(time)
b.select_list(:id => "makeResParty").select("#{guests} Guests")
b.text_field(:id, 'searchRestaurantText').set(restaurant)
sleep 1
b.element(:class => 'autoCompleteHighlight').click
b.button(:id, 'makeResSubmit').click
sleep 2
if b.p(:id => 'NoAvailableTimes').present?
puts "#{date} - No times :("
else
puts "#{date} - Got some times!"
b.labels(:class => 'reserveFormLabel').each do |label|
puts " #{label.text}"
end
end
end
def main
b = Watir::Browser.new :firefox
config = YAML.load_file('dining.yml')
guests = config["guests"]
time = config["time"]
config["dates"].each do |date|
b.goto 'http://disneyworld.disney.go.com/reservations/dining/'
find_reservation_times_for(b, "'Ohana", date, guests, time)
end
b.close
rescue => e
puts e.message
puts e.backtrace.join("\n")
end
begin
main
rescue => e
puts e.message
puts e.backtrace
end
guests: 6
time: 'Dinner'
dates:
- 11/29/2011
- 11/30/2011
- 12/01/2011
- 12/02/2011
- 12/03/2011
require 'rubygems'
require 'watir-webdriver'
require 'yaml'
NUMBER_OF_ADULTS = 2
CHILDREN_AGES = [7,5]
def set_vacation_options(b, arrival_date, departure_date)
b.select_list(:id => 'partyMix_AdultsTotal').select(NUMBER_OF_ADULTS)
b.select_list(:id => 'partyMix_ChildrenTotal').select(CHILDREN_AGES.length)
CHILDREN_AGES.each_with_index do |age, i|
b.select_list(:id => "partyMix_Child#{i+1}").select(age)
end
b.text_field(:id, 'travelDates_Arrival').set(arrival_date)
b.text_field(:id, 'travelDates_Departure').set(departure_date)
b.button(:id, 'continue').click
end
def select_any_value_resort(b)
b.button(:id, 'categorySelection_VALUE_SelectBtn').wait_until_present
b.button(:id, 'categorySelection_VALUE_SelectBtn').click
end
def select_value_resort(b, resort)
b.link(:id, 'CategoryLink_VALUE').wait_until_present
b.link(:id, 'CategoryLink_VALUE').click
sleep 2
resort_button = b.h5(:text => /#{resort}/).parent.input(:value => "Select >>")
if (resort_button.exists?)
resort_button.click
else
puts "Looks like your resort: '#{resort}' is not available"
end
end
def get_price(b)
b.element(:class => 'hubTabTotalPrice').wait_until_present
orig = b.element(:class => 'hubTabTotalPrice').text
orig.split[0]
end
def get_cheapest_price(b)
price = get_price(b)
cheaper_room_radio = b.radios(:id => /hub_RoomType/).first
if cheaper_room_radio.exists?
cheaper_room_radio.set
b.button(:id => 'roomTypeUpdateButton').click
sleep 3
price = get_price(b)
end
price
end
def get_prices_from_disney_for(arrival, departure, resort)
b = Watir::Browser.new :firefox
b.goto 'http://bookwdw.reservations.disney.go.com/'
set_vacation_options(b, arrival, departure)
if resort && resort.upcase != "ANY"
select_value_resort(b, resort)
else
select_any_value_resort(b)
end
price = get_cheapest_price(b)
resort = b.dt(:text => /Disney's /).text
puts "#{arrival} - #{departure} : #{resort} for #{price}"
b.close
rescue => e
b.close
end
def main
config = YAML.load_file('config.yml')
resort = config["resort"]
config["dates"].each do |date|
arrival = date["arrival"]
departure = date["departure"]
get_prices_from_disney_for(arrival, departure, resort)
end
end
begin
main
rescue => e
puts e.message
puts e.backtrace
end
@Trevoke
Copy link

Trevoke commented Sep 8, 2011

Hot.
What were those commercials with William Shatner? 'Cause he just got owned.

@olore
Copy link
Author

olore commented Sep 9, 2011

:) thanks man. More to come!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment