Add a basic extra get

This commit is contained in:
PAlexanderFranklin 2023-09-01 23:31:17 -07:00
parent 5f4abc1a43
commit a1762348fe
2 changed files with 57 additions and 10 deletions

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
node_modules
options.json
results.json
results.json
uberResults.json
lyftResults.json

View File

@ -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 {