Last active
February 1, 2021 20:28
-
-
Save arastu/9224674e5c05ecda6bba228f090d00f1 to your computer and use it in GitHub Desktop.
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
/** | |
* 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, ",")); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Thank you for this.
It's very cool.
I modified with new API versions and Discounts calculations here.