From a1762348fe202c663cf7a1cd8245a3d406af97df Mon Sep 17 00:00:00 2001 From: PAlexanderFranklin Date: Fri, 1 Sep 2023 23:31:17 -0700 Subject: [PATCH] Add a basic extra get --- .gitignore | 4 +++- src/index.js | 63 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 5a65d75..f59f619 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules options.json -results.json \ No newline at end of file +results.json +uberResults.json +lyftResults.json \ No newline at end of file diff --git a/src/index.js b/src/index.js index e76f4c7..51378a1 100644 --- a/src/index.js +++ b/src/index.js @@ -7,8 +7,8 @@ function sleep(ms) { } async function main() { let options = JSON.parse(fs.readFileSync("./options.json", "utf8")) - if (!fs.existsSync("./results.json")) { - fs.writeFileSync("./results.json", "") + if (!fs.existsSync("./uberResults.json")) { + fs.writeFileSync("./uberResults.json", "") } const browser = await puppeteer.launch({ headless: false, @@ -71,6 +71,9 @@ async function main() { } } console.log("after sleep loop") + + let uberJSON = [] + let paginationOption = {} while (true) { let res = await fetch( @@ -86,23 +89,65 @@ async function main() { }, ) let body = await res.json() - body.data.activities.map((activity) => { - activity.recognizedAt = (activity.recognizedAt ?? 1) * 1000 + let trips = body.data.activities.map(async (activity) => { if (activity.formattedTotal == "$0.00") { return "" } - delete activity.routing - delete activity.uuid - if (activity.tripMetaData?.mapUrl) { - delete activity.tripMetaData.mapUrl + if (activity.type == "QUEST") { + // These are all duplicates of MISC items. + return "" + } + if (activity.type == "TRIP" || activity.type == "CT") { + // Trip or Share + // make sure to get the activity.tripMetaData.pickupAddress and dropOffAddress. + let res = await fetch( + "https://drivers.uber.com/earnings/api/getTrip?localeCode=en", + { + method: "POST", + body: JSON.stringify({ + tripUUID: activity.uuid, + }), + headers: usefulRequestHeaders, + }, + ) + let body = await res.json() + let cards = body?.data?.cards + let breakdown = cards?.find( + (card) => card.type == "TripAllPartiesBreakdownCard", + ) + if (breakdown) { + let components = breakdown.components?.filter((comp) => { + return ( + comp.type != "header" && + comp.type != "divider" && + comp.type != "collapsableSection" + ) + }) + if (components.length) { + return components + } + } + return body + } + if (activity.type == "MISC") { + activity.recognizedAt = (activity.recognizedAt ?? 1) * 1000 + delete activity.routing + delete activity.uuid + delete activity.status + if (activity.tripMetaData?.mapUrl) { + delete activity.tripMetaData.mapUrl + } + return activity } - fs.appendFileSync("./results.json", JSON.stringify(activity)) }) + let tripResults = await utils.settlePromises(trips) + uberJSON = [...uberJSON, ...tripResults] if (!body.data.pagination.hasMoreData) { break } paginationOption.cursor = body.data.pagination.nextCursor } + fs.appendFileSync("./uberResults.json", `, ${JSON.stringify(uberJSON)}`) } catch (err) { console.error("Critical failure", err) } finally {