Created
December 6, 2022 04:06
-
-
Save tvc97/12a69b647a22c63242bd2e005dbcfbca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var from = '2345-01-01'; | |
var to = '0'; | |
function getPageTotal(offset = 0) { | |
const req = new XMLHttpRequest(); | |
req.open( | |
'GET', | |
`https://food.grab.com/proxy/foodweb/v2/order/history?input.limit=100&input.offset=${offset}`, | |
false | |
); | |
req.send(); | |
a = JSON.parse(req.responseText); | |
if (!a.response.orders.length) return 0; | |
a.response.orders.forEach((item) => { | |
from = item.createdAt < from ? item.createdAt : from; | |
to = item.createdAt > to ? item.createdAt : to; | |
}); | |
return a.response.orders.reduce( | |
(prev, next) => | |
next.snapshotDetail.cartWithQuote.totalQuoteInMin | |
.reducedPriceInMinorUnit + prev, | |
0 | |
); | |
} | |
function formatMoney(value) { | |
return Intl.NumberFormat('vi-VN').format(value); | |
} | |
var currentOffset = 0; | |
var total = 0; | |
var calc = async () => { | |
while ((pageTotal = getPageTotal(currentOffset))) { | |
total += pageTotal; | |
console.log(`Offset ${currentOffset}: ${formatMoney(pageTotal)}`); | |
currentOffset += 100; | |
await new Promise((rs) => setTimeout(rs, 500)); | |
} | |
console.log(`From ${from} to ${to}`); | |
console.log(`Total: ${formatMoney(total)}`); | |
}; | |
calc(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment