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 node_modules
options.json options.json
results.json results.json
uberResults.json
lyftResults.json

View File

@ -7,8 +7,8 @@ function sleep(ms) {
} }
async function main() { async function main() {
let options = JSON.parse(fs.readFileSync("./options.json", "utf8")) let options = JSON.parse(fs.readFileSync("./options.json", "utf8"))
if (!fs.existsSync("./results.json")) { if (!fs.existsSync("./uberResults.json")) {
fs.writeFileSync("./results.json", "") fs.writeFileSync("./uberResults.json", "")
} }
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
headless: false, headless: false,
@ -71,6 +71,9 @@ async function main() {
} }
} }
console.log("after sleep loop") console.log("after sleep loop")
let uberJSON = []
let paginationOption = {} let paginationOption = {}
while (true) { while (true) {
let res = await fetch( let res = await fetch(
@ -86,23 +89,65 @@ async function main() {
}, },
) )
let body = await res.json() let body = await res.json()
body.data.activities.map((activity) => { let trips = body.data.activities.map(async (activity) => {
activity.recognizedAt = (activity.recognizedAt ?? 1) * 1000
if (activity.formattedTotal == "$0.00") { if (activity.formattedTotal == "$0.00") {
return "" return ""
} }
delete activity.routing if (activity.type == "QUEST") {
delete activity.uuid // These are all duplicates of MISC items.
if (activity.tripMetaData?.mapUrl) { return ""
delete activity.tripMetaData.mapUrl }
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) { if (!body.data.pagination.hasMoreData) {
break break
} }
paginationOption.cursor = body.data.pagination.nextCursor paginationOption.cursor = body.data.pagination.nextCursor
} }
fs.appendFileSync("./uberResults.json", `, ${JSON.stringify(uberJSON)}`)
} catch (err) { } catch (err) {
console.error("Critical failure", err) console.error("Critical failure", err)
} finally { } finally {