Add a basic extra get
This commit is contained in:
parent
5f4abc1a43
commit
a1762348fe
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
node_modules
|
||||
options.json
|
||||
results.json
|
||||
results.json
|
||||
uberResults.json
|
||||
lyftResults.json
|
63
src/index.js
63
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user