Last active
May 11, 2018 00:57
-
-
Save NandoSangenetto/6bd970c8f77c68fe405e89cb8de9b5fa to your computer and use it in GitHub Desktop.
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
let rides = []; | |
let lastRideId = undefined; | |
const getRides = () => { | |
const tripNodes = Array.from( | |
document.querySelectorAll(".trip-expand__origin") | |
); | |
const id = tripNodes[0].dataset.target.replace("#trip-", ""); | |
const hasNewRides = lastRideId !== id; | |
if (hasNewRides) { | |
const trips = tripNodes.map(trip => { | |
const share = trip.querySelector(".color--neutral"); | |
const divisor = share ? Math.floor(share.textContent.match(/( [A-Z][A-z ]+)+/g).map(name => name.substr(1)).length + 1) : 1; | |
const priceNode = trip.children[3].textContent.trim().match(/(?<price>(^(?![\s\S])|[0-9\. ]+)|Canceled)/).groups.price; | |
const price = priceNode !== "Canceled" ? (priceNode / divisor).toFixed(2) : priceNode; | |
return { | |
id: trip.dataset.target.replace("#trip-", ""), | |
date: trip.children[1].textContent.split(/(You|This)/)[0], | |
driver: trip.children[2].textContent, | |
price, | |
origin: trip.nextSibling.querySelectorAll("h6.flush")[0].textContent, | |
destination: trip.nextSibling.querySelectorAll("h6.flush")[1].textContent | |
} | |
}); | |
lastRideId = trips[0].id; | |
rides = rides.concat(trips); | |
const nextPage = document.querySelector(".pagination__next"); | |
if (nextPage) { | |
nextPage.click(); | |
} else { | |
clearInterval(interval); | |
} | |
} | |
}; | |
const interval = setInterval(getRides, 1000); | |
const objToCSV = (obj) => obj.map((element) => `"${Object.values(element).join('","')}"`).join("\n"); | |
// Just run console.log(objToCSV(rides)) after get all data :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment