Created
August 5, 2017 23:31
-
-
Save agentcooper/d17a776f9948f8d3f326447d0018ccd2 to your computer and use it in GitHub Desktop.
Uber EATS statistics
This file contains hidden or 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
/* | |
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