Print to file
This commit is contained in:
parent
c722fd3483
commit
64ff788ff6
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
options.json
|
options.json
|
||||||
|
results.json
|
@ -1,3 +1,5 @@
|
|||||||
{
|
{
|
||||||
"uberPhoneNumber": "1234567891"
|
"uberPhoneNumber": "1234567891",
|
||||||
|
"startDateIso": "2023-01-01",
|
||||||
|
"endDateIso": "2023-12-31"
|
||||||
}
|
}
|
||||||
|
17
src/index.js
17
src/index.js
@ -7,6 +7,9 @@ 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")) {
|
||||||
|
fs.writeFileSync("./results.json", "")
|
||||||
|
}
|
||||||
const browser = await puppeteer.launch({
|
const browser = await puppeteer.launch({
|
||||||
headless: false,
|
headless: false,
|
||||||
ignoreHTTPSErrors: true,
|
ignoreHTTPSErrors: true,
|
||||||
@ -75,8 +78,8 @@ async function main() {
|
|||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
startDateIso: "2023-04-01",
|
startDateIso: options.startDateIso ?? "2023-04-01",
|
||||||
endDateIso: "2023-04-31",
|
endDateIso: options.endDateIso ?? "2023-04-31",
|
||||||
paginationOption,
|
paginationOption,
|
||||||
}),
|
}),
|
||||||
headers: usefulRequestHeaders,
|
headers: usefulRequestHeaders,
|
||||||
@ -84,11 +87,11 @@ async function main() {
|
|||||||
)
|
)
|
||||||
let body = await res.json()
|
let body = await res.json()
|
||||||
body.data.activities.map((activity) => {
|
body.data.activities.map((activity) => {
|
||||||
console.log(
|
delete activity.routing
|
||||||
new Date(activity.recognizedAt * 1000),
|
if (activity.tripMetaData?.mapUrl) {
|
||||||
activity.formattedTotal,
|
delete activity.tripMetaData.mapUrl
|
||||||
activity.routing,
|
}
|
||||||
)
|
fs.appendFileSync("./results.json", JSON.stringify(activity))
|
||||||
})
|
})
|
||||||
if (!body.data.pagination.hasMoreData) {
|
if (!body.data.pagination.hasMoreData) {
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user