Created
February 28, 2018 12:28
-
-
Save seunlanlege/719f0f0fff094ad6b6a68cf43aed2566 to your computer and use it in GitHub Desktop.
A script to compute the total amount you've spent on uber rides.
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
/* | |
you'll need to run `yarn add axios cheerio` to add the dependencies | |
then `node compute.js` | |
*/ | |
const axios = require("axios") | |
const fs = require("fs") | |
const cheerio = require("cheerio") | |
async function main() { | |
let sum = 0 | |
let i = 1 | |
while (true) { | |
const { data } = await axios.get("https://riders.uber.com/trips?page=" + i, { | |
headers: { | |
Cookie: | |
"login to riders.uber.com and copy your cookies from the developer console's network tab, note that cookies are to be formatted here as key1=value1; key2=value2;" | |
} | |
}) | |
const $ = cheerio.load(data) | |
let node = $("h3") | |
if (node.contents().length == 2) { | |
break | |
} | |
node.each(function(el) { | |
let text = $(this).text() | |
if (text.indexOf("NGN") === -1) { // replace this with your currency. | |
return | |
} | |
text = text.replace("NGN", "") //replace this with your currency synbol. | |
text = text.replace(",", "") | |
text = parseInt(text) | |
sum += text | |
}) | |
i += 1 | |
} | |
console.log("NGN :", sum) //replace this with your currency symbol. | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment