Skip to content

Instantly share code, notes, and snippets.

@adamdonahue
Created March 3, 2018 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamdonahue/1ac1b397fcf17d4508961ea7cba20276 to your computer and use it in GitHub Desktop.
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
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