add filtering

This commit is contained in:
PAlexanderFranklin 2023-09-02 16:54:54 -07:00
parent a1762348fe
commit 07463d3bff

View File

@ -7,9 +7,6 @@ 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("./uberResults.json")) {
fs.writeFileSync("./uberResults.json", "")
}
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
headless: false, headless: false,
ignoreHTTPSErrors: true, ignoreHTTPSErrors: true,
@ -89,7 +86,7 @@ async function main() {
}, },
) )
let body = await res.json() let body = await res.json()
let trips = body.data.activities.map(async (activity) => { let trips = body?.data?.activities?.map(async (activity) => {
if (activity.formattedTotal == "$0.00") { if (activity.formattedTotal == "$0.00") {
return "" return ""
} }
@ -97,6 +94,18 @@ async function main() {
// These are all duplicates of MISC items. // These are all duplicates of MISC items.
return "" return ""
} }
if (activity.type == "MISC" || activity.activityTitle == "Delivery") {
return {
uuid: activity.uuid,
recognizedAt: new Date(
(activity.recognizedAt ?? 1) * 1000,
).toISOString(),
pickupAddress: activity.tripMetaData?.pickupAddress,
dropOffAddress: activity.tripMetaData?.dropOffAddress,
total: Number(activity.formattedTotal),
type: activity.activityTitle,
}
}
if (activity.type == "TRIP" || activity.type == "CT") { if (activity.type == "TRIP" || activity.type == "CT") {
// Trip or Share // Trip or Share
// make sure to get the activity.tripMetaData.pickupAddress and dropOffAddress. // make sure to get the activity.tripMetaData.pickupAddress and dropOffAddress.
@ -111,10 +120,13 @@ async function main() {
}, },
) )
let body = await res.json() let body = await res.json()
let cards = body?.data?.cards let unparsedData = body
let breakdown = cards?.find( let cards = body?.data?.cards?.filter((card) => {
(card) => card.type == "TripAllPartiesBreakdownCard", return card.type != "MapCard" && card.type != "TripStatsCard"
) })
let breakdown =
cards?.find((card) => card.type == "TripAllPartiesBreakdownCard") ||
cards?.find((card) => card.type == "TripBreakdownCard")
if (breakdown) { if (breakdown) {
let components = breakdown.components?.filter((comp) => { let components = breakdown.components?.filter((comp) => {
return ( return (
@ -123,31 +135,40 @@ async function main() {
comp.type != "collapsableSection" comp.type != "collapsableSection"
) )
}) })
if (components.length) { if (components?.length) {
return components unparsedData = components
} }
} }
return body if (cards?.length) {
unparsedData = cards
} }
if (activity.type == "MISC") { return {
activity.recognizedAt = (activity.recognizedAt ?? 1) * 1000 uuid: activity.uuid,
delete activity.routing recognizedAt: new Date(
delete activity.uuid (activity.recognizedAt ?? 1) * 1000,
delete activity.status ).toISOString(),
if (activity.tripMetaData?.mapUrl) { pickupAddress: activity.tripMetaData?.pickupAddress,
delete activity.tripMetaData.mapUrl dropOffAddress: activity.tripMetaData?.dropOffAddress,
total: Number(activity.formattedTotal),
type: activity.activityTitle,
unparsedData,
} }
return activity
} }
}) })
if (trips) {
let tripResults = await utils.settlePromises(trips) let tripResults = await utils.settlePromises(trips)
uberJSON = [...uberJSON, ...tripResults] uberJSON = [...uberJSON, ...tripResults]
} else {
let failedRequest = { failedRequest: res, body }
console.error(failedRequest)
uberJSON = [...uberJSON, failedRequest]
}
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)}`) fs.writeFileSync("./uberResults.json", JSON.stringify(uberJSON))
} catch (err) { } catch (err) {
console.error("Critical failure", err) console.error("Critical failure", err)
} finally { } finally {