Created
March 3, 2018 20:22
-
-
Save adamdonahue/1ac1b397fcf17d4508961ea7cba20276 to your computer and use it in GitHub Desktop.
Quick-and-dirty script to calculate my total Uber spend - must be run via rider.uber.com after log-in
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
async function myUberSpend() { | |
async function costForPage(pageNumber) { | |
const response = await fetch(`trips?page=${pageNumber}`, { | |
credentials: 'include' | |
}); | |
const text = await response.text(); | |
const prices = $(text).find("td.text--right"); | |
if (!prices.length) return; | |
let costForPage = 0.0; | |
for (var i = 0; i < prices.length; i++) { | |
textPrice = prices[i].textContent.trim(); | |
if (!/^\$\d+\.\d+$/.test(textPrice)) continue; | |
costForPage += parseFloat(textPrice.slice(1)); | |
} | |
return costForPage; | |
} | |
let currentPage = 1; | |
let totalCost = 0.0; | |
while (true) { | |
const pageCost = await costForPage(currentPage); | |
if (pageCost === undefined) break; | |
totalCost += pageCost; | |
currentPage++; | |
} | |
return totalCost; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment