Skip to content

Instantly share code, notes, and snippets.

@arastu
Last active February 1, 2021 20:28
Show Gist options
  • Save arastu/9224674e5c05ecda6bba228f090d00f1 to your computer and use it in GitHub Desktop.
Save arastu/9224674e5c05ecda6bba228f090d00f1 to your computer and use it in GitHub Desktop.
/**
* Open https://app.snapp.ir
* Login with your credentials
* Copy and pasting this code in developer tools console
* Waiting... :)
*/
(async function () {
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
}
const token = JSON.parse(localStorage.getItem('user')).token;
const headers = new Headers();
const url = 'https://web-api.snapp.ir/api/v1/ride/history';
const query = '?page=';
let total = 0;
let page = 1;
headers.append('Authorization', token);
headers.append('Content-Type', 'application/json');
while (true) {
const response = await fetch(`${url}${query}${page}`, {
method: 'GET',
headers
});
await sleep(3000)
const data = await response.json();
if (data.rides.length === 0) {
break;
}
total += data.rides
.filter(it => it.latest_ride_status !== 6 && it.latest_ride_status !== 7)
.map(it => it.price)
.reduce((sum, price) => sum + price, 0);
page += 1;
}
console.log(total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
}());
@safeamiiir
Copy link

Hi,
Thank you for this.
It's very cool.
I modified with new API versions and Discounts calculations here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment