-
-
Save safeamiiir/a1ae337f29ea7c2c1de1cc4039b46f48 to your computer and use it in GitHub Desktop.
Total payed snapp
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 = localStorage.getItem('accessToken'); | |
const headers = new Headers(); | |
const url = 'https://app.snapp.taxi/api/api-base/v2/passenger/ride/history'; | |
const query = '?page='; | |
let total = 0; | |
let discounts = 0; | |
let page = 1; | |
headers.append('Authorization', `Bearer ${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(); | |
console.dir(`Wait... (in page ${page})`) | |
if (data.data.rides.length === 0) { | |
break; | |
} | |
total += data.data.rides | |
.filter(it => it.latest_ride_status !== 6 && it.latest_ride_status !== 7) | |
.map(it => it.final_price) | |
.reduce((sum, price) => sum + price, 0); | |
discounts += data.data.rides | |
.filter(it => it.latest_ride_status !== 6 && it.latest_ride_status !== 7) | |
.map(it => it.rows) | |
.map( it => it.filter( row => row.title === "تخفیف(ها)")[0]) | |
.filter ( it => it !== undefined ) | |
.reduce( (sum, discount) => sum + discount.description, 0 ) | |
page += 1; | |
} | |
total /= 10; //convert into Toman | |
discounts /= 10; //convert into Toman | |
console.dir("You Payed: ") | |
console.dir(total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")); | |
console.dir("TOMAN") | |
console.dir("------") | |
console.dir("Discounts: ") | |
console.dir((-discounts).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")); | |
console.dir("TOMAN") | |
console.dir("------") | |
console.dir("Trips Total: ") | |
console.dir(( total - discounts ).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), "Toman"); | |
console.dir("TOMAN") | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment