Created
March 14, 2018 20:24
-
-
Save takethefake/8fd5e71f139746981e483985d8d71e0f to your computer and use it in GitHub Desktop.
Find a Place To Get a Helmet
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
const fetch = require("node-fetch"); | |
const locations = [ | |
"Kärnten", | |
"Bad Kleinkirchheim", | |
"Heiligenblut", | |
"Katschberg", | |
"Kötschach-Mauthen", | |
"Mallnitz", | |
"Niederösterreich", | |
"Aspangberg St. Peter", | |
"Gmünd", | |
"Lackenhof", | |
"Mönichkirchen", | |
"Semmering", | |
"Oberösterreich", | |
"Hinterstoder", | |
"Obertraun", | |
"Salzburg", | |
"Abtenau", | |
"Alpendorf bei St. Johann im Pongau", | |
"Altenmarkt", | |
"Bad Gastein", | |
"Bad Hofgastein", | |
"Bischofshofen", | |
"Bramberg am Wildkogel", | |
"Eben im Pongau", | |
"Filzmoos", | |
"Flachau", | |
"Großarl", | |
"Hinterglemm", | |
"Hochkrimml", | |
"Kaprun", | |
"Königsleiten-Wald", | |
"Krimml", | |
"Lofer", | |
"Maria Alm", | |
"Mühlbach am Hochkönig", | |
"Neukirchen am Großvenediger", | |
"Obertauern", | |
"Rauris", | |
"Saalbach", | |
"Saalfelden", | |
"St. Michael", | |
"Uttendorf", | |
"Wagrain", | |
"Werfenweng", | |
"Zauchensee", | |
"Zell am See", | |
"Steiermark", | |
"Donnersbach", | |
"Gröbming", | |
"Irdning", | |
"Planneralm", | |
"Ramsau", | |
"Riesneralm", | |
"Rohrmoos/Schladming", | |
"Schladming", | |
"St. Georgen/Murau", | |
"Tauplitz", | |
"Tirol", | |
"Achenkirch", | |
"Alpbach", | |
"Berwang", | |
"Bichlbach", | |
"Brixen im Thale", | |
"Ehrwald", | |
"Ellmau", | |
"Feichten/Kaunertal", | |
"Fieberbrunn", | |
"Fiss", | |
"Fliess", | |
"Fügen", | |
"Fulpmes", | |
"Galtür", | |
"Gerlos", | |
"Going", | |
"Gries im Sellrain", | |
"Hintertux", | |
"Hochfügen", | |
"Holzgau", | |
"Hopfgarten", | |
"Igls", | |
"Imst", | |
"Ischgl", | |
"Itter", | |
"Jerzens", | |
"Jochberg bei Kitzbühel", | |
"Kals in Osttirol", | |
"Kaltenbach", | |
"Kappl", | |
"Kirchberg", | |
"Kitzbühel", | |
"Kühtai", | |
"Lanersbach", | |
"Lermoos", | |
"Matrei in Osttirol", | |
"Maurach", | |
"Tirol", | |
"Mayrhofen", | |
"Nauders", | |
"Neustift", | |
"Obergurgl", | |
"Oberndorf", | |
"Ötz", | |
"Pertisau am Achensee", | |
"Pettneu", | |
"Ried im Oberinntal", | |
"Scheffau", | |
"See im Paznaun", | |
"Seefeld", | |
"Serfaus", | |
"Sillian in Osttirol", | |
"Sölden", | |
"Söll", | |
"St. Anton am Arlberg", | |
"St. Jakob im Defereggental in Osttirol", | |
"St. Johann in Tirol", | |
"St. Leonhard", | |
"Tannheim", | |
"Tulfes", | |
"Telfes im Stubai", | |
"Vent", | |
"Westendorf", | |
"Wildschönau-Niederau", | |
"Zams", | |
"Zell am Ziller", | |
"Vorarlberg", | |
"Au/Schoppernau", | |
"Brand", | |
"Gaschurn-Partenen", | |
"Hirschegg", | |
"Lech", | |
"Mellau/Damüls", | |
"Mittelberg", | |
"Riezlern", | |
"Schruns-Tschagguns", | |
"St. Gallenkirch", | |
"Warth am Arlberg/Schröcken" | |
]; | |
const API_KEY = "********************************************"; | |
const origin = "Darmstadt"; | |
const destination = "Pitztal"; | |
const createUrl = waypoint => | |
encodeURI( | |
`https://maps.googleapis.com/maps/api/directions/json?origin=${origin}&destination=${destination}&waypoints=${waypoint}&key=${API_KEY}` | |
); | |
const getDistance = (waypoint = null) => | |
fetch(createUrl(waypoint)) | |
.then(resp => resp.json()) | |
.then(jsonResp => { | |
//console.log(jsonResp); | |
//console.log(jsonResp.routes[0]); | |
try { | |
const legs = jsonResp.routes[0]["legs"]; | |
const distance0 = legs[0]["distance"]["value"]; | |
const distance1 = legs[1]["distance"]["value"]; | |
const point = { waypoint, distance0, distance1 }; | |
return point; | |
} catch (e) { | |
return { waypoint, distance0: "?", distance1: "?" }; | |
} | |
}) | |
.catch(console.log); | |
const getDistances = waypointArr => | |
Promise.all(waypointArr.map(waypoint => getDistance(waypoint))); | |
const main = async () => { | |
const distances = await getDistances(locations); | |
const sortedDist = distances | |
.filter(loc => loc.distance0 + loc.distance1 < 550000) | |
.sort((a, b) => b.distance1 - a.distance1); | |
console.log(sortedDist); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment