Skip to content

Instantly share code, notes, and snippets.

@rafasf
Created February 10, 2017 13:51
Show Gist options
  • Save rafasf/bd42b9bc53dcd947cd91c1cd0d6ebf50 to your computer and use it in GitHub Desktop.
Save rafasf/bd42b9bc53dcd947cd91c1cd0d6ebf50 to your computer and use it in GitHub Desktop.
Mountain Collective Flights
#!/usr/bin/env ruby
require 'json'
resorts_source = 'resorts.json'
origins = ['JFK', 'EWR', 'LGA']
depart_date = '2017-02-23'
return_date = '2017-02-26'
def url_for(origins, destinations, depart_date, return_date)
"https://www.google.com/flights/#search;f=#{origins};t=#{destinations};d=#{depart_date};r=#{return_date};a=STAR_ALLIANCE;mc=m"
end
resorts = JSON.parse(open(resorts_source).read, symbolize_names: true)
longest_name = resorts
.map { |r| r[:name] }
.concat(["to all locations"])
.max_by(&:length)
.length
resorts.map do |resort|
url = url_for(
origins.join(','),
resort[:airports].join(','),
depart_date,
return_date)
printf("%-#{longest_name}s %s\n", resort[:name], url)
end
all_airports = resorts
.map { |resort| resort[:airports] }
.flatten
.uniq
.join(',')
printf(
"%-#{longest_name}s %s\n",
'To all locations',
url_for(origins.join(','), all_airports, depart_date, return_date))
[
{
"name": "Snowbird",
"url": "http://www.snowbird.com",
"airports": ["SLC"]
},
{
"name": "Alta",
"url": "http://www.alta.com",
"airports": ["SLC"]
},
{
"name": "Aspen Snowmass",
"url": "https://www.aspensnowmass.com",
"airports": ["ASE"]
},
{
"name": "Jackson Hole",
"url": "http://www.jacksonhole.com",
"airports": ["JAC"]
},
{
"name": "Mammoth",
"url": "http://www.mammothmountain.com",
"airports": ["MMH"]
},
{
"name": "Revelstroke",
"url": "http://www.revelstokemountainresort.com",
"airports": ["YRV", "YLW"]
},
{
"name": "Banff",
"url": "https://www.skibig3.com",
"airports": ["YYC"]
},
{
"name": "Coronet Peak",
"url": "https://www.nzski.com",
"airports": ["ZQN"]
},
{
"name": "Squaw Alpine",
"url": "http://squawalpine.com",
"airports": ["RNO"]
},
{
"name": "Sun Valley",
"url": "https://www.sunvalley.com",
"airports": ["SUN"]
},
{
"name": "Taos",
"url": "http://www.skitaos.com",
"airports": ["SAF", "ABQ"]
},
{
"name": "Telluride",
"url": "http://www.tellurideskiresort.com",
"airports": ["TEX", "MTJ", "GJT", "DRO"]
},
{
"name": "Stowe",
"url": "https://www.stowe.com",
"airports": ["BTV"]
},
{
"name": "Thredbo",
"url": "https://www.thredbo.com.au",
"airports": ["COM"]
},
{
"name": "Whistler Blackcomb",
"url": "https://www.whistlerblackcomb.com",
"airports": ["YVR"]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment