Skip to content

Instantly share code, notes, and snippets.

@tvc97
Created December 6, 2022 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvc97/12a69b647a22c63242bd2e005dbcfbca to your computer and use it in GitHub Desktop.
Save tvc97/12a69b647a22c63242bd2e005dbcfbca to your computer and use it in GitHub Desktop.
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