Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Uber EATS statistics
/*
Uber EATS statistics
1. Go to https://www.ubereats.com, click **Sign in**
2. Enter your credentials, sign in
3. Open JavaScript console (CMD + Option + J)
4. Copy following code and paste it into the console, hit enter
*/
const fetchOrders = async () => {
const res = await fetch('/rtapi/eats/v1/eaters/me/orders?limit=1000', {
credentials: 'include',
});
const json = await res.json();
return json.orders;
};
const getTotal = order =>
Math.ceil(order.checkoutInfo.find(part => part.key === 'eats_fare.total').rawValue);
const groupBy = (orders, computeKey) =>
Object.entries(
orders.reduce((acc, order) => {
const key = computeKey(order);
if (!acc[key]) {
acc[key] = { orders: [], totalPrice: 0 };
}
acc[key].orders.push(order);
acc[key].totalPrice += getTotal(order);
return acc;
}, {})
);
const byMonth = orders =>
groupBy(orders, order => {
const date = new Date(order.completionStatus.completionTime);
const key = `${String(date.getMonth() + 1).padStart(2, '0')}/${date.getFullYear()}`;
return key;
});
const byTitle = orders =>
groupBy(orders, order => order.store.title)
.map(([title, group]) => ({ title, group }))
.sort((a, b) => b.group.totalPrice - a.group.totalPrice);
const print = allOrders => {
let s = ``;
s += `Total orders: ${allOrders.length}\n\n`;
for (const [month, { orders, totalPrice }] of byMonth(allOrders)) {
s += `${month}\t${totalPrice}\n`;
for (const { title, group } of byTitle(orders)) {
s += `${group.orders.length}\t${group.totalPrice}\t${title}\n`;
}
s += `\n`;
}
return s;
};
const main = async () => {
const allOrders = await fetchOrders();
document.write(`<pre>${print(allOrders)}</pre>`);
console.log('Done!');
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment