Created
February 10, 2017 13:51
-
-
Save rafasf/bd42b9bc53dcd947cd91c1cd0d6ebf50 to your computer and use it in GitHub Desktop.
Mountain Collective Flights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"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