Skip to content

Instantly share code, notes, and snippets.

@SamadiPour
Last active December 26, 2024 22:05
Show Gist options
  • Save SamadiPour/a18b1e186deac76c4a95fa108d02a6ea to your computer and use it in GitHub Desktop.
Save SamadiPour/a18b1e186deac76c4a95fa108d02a6ea to your computer and use it in GitHub Desktop.
Snappfood Spent money
cookies = Object.fromEntries(document.cookie.split('; ').map(c => c.split('=')));
let UDID = cookies.UDID;
let jwt = cookies[['jwt-access_token']] ?? JSON.parse(window.localStorage.JWT ?? '{}').access_token;
var myHeaders = new Headers();
myHeaders.append("authority", "snappfood.ir");
myHeaders.append("accept", "application/json, text/plain, */*");
myHeaders.append("accept-language", "en-US,en;q=0.9,fa;q=0.8");
myHeaders.append("authorization", "Bearer " + jwt);
myHeaders.append("content-type", "application/x-www-form-urlencoded");
myHeaders.append("referer", "https://snappfood.ir/profile/orders");
myHeaders.append("sec-ch-ua", "\".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"");
myHeaders.append("sec-ch-ua-mobile", "?1");
myHeaders.append("sec-ch-ua-platform", "\"Android\"");
myHeaders.append("sec-fetch-dest", "empty");
myHeaders.append("sec-fetch-mode", "cors");
myHeaders.append("sec-fetch-site", "same-origin");
myHeaders.append("user-agent", "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Mobile Safari/537.36");
const requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
let pageSize = 1000;
let pageNumber = 0;
let allOrders = [];
let count = 1;
while (pageNumber * pageSize < count) {
console.log(`Getting ${pageNumber * pageSize} - ${(pageNumber + 1) * pageSize}...`);
let response = await fetch(`https://snappfood.ir/mobile/v1/order/reorder?optionalClient=WEBSITE&client=WEBSITE&deviceType=WEBSITE&appVersion=8.1.1&UDID=${UDID}&page=${pageNumber}&size=${pageSize}&locale=fa`, requestOptions);
const responseData = await response.json();
const orders = responseData.data.orders;
count = responseData.data.count ?? 0;
if (orders.length === 0) break;
allOrders = allOrders.concat(orders);
pageNumber++;
}
let price = 0;
let discount = 0;
for (let i = 0; i < allOrders.length; i++) {
let order = allOrders[i];
if (!order.orderCanceled) {
price += order.totalPrice;
discount += order.sumAllDiscount;
}
}
const today = new Date();
const oldestOrderDate = new Date(allOrders.at(-1).startedAt);
const timeDiff = today.getTime() - oldestOrderDate.getTime();
const daysDiff = Math.floor(timeDiff / (1000 * 3600 * 24));
const yearsDiff = Math.floor(daysDiff / 365);
const remainingDays = daysDiff % 365;
const conversionResponse = await fetch(`https://raw.githubusercontent.com/SamadiPour/rial-exchange-rates-archive/data/gregorian_imp.min.json`);
const conversionResponseData = await conversionResponse.json();
const conversionRates = new Map(
Object.entries(conversionResponseData).map(([key, value]) => [key, value.usd.buy ?? value.usd.sell])
);
const lastConversionRate = [...conversionRates.values()].at(-1)
let usd = 0;
for (let i = 0; i < allOrders.length; i++) {
let order = allOrders[i];
if (!order.orderCanceled) {
let dateString = new Date(order.startedAt).toLocaleDateString('en-CA', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/-/g, '/');
let usdRate = conversionRates.get(dateString) ?? lastConversionRate;
usd += order.totalPrice / usdRate;
}
}
console.log('%c---------------', 'color: #888; font-weight: bold;');
console.log('%cTotal order:%c %s', 'color: #3498db; font-weight: bold;', 'color: #c0c0c0;', allOrders.length);
console.log('%cTotal spent:%c %s Toman', 'color: #3498db; font-weight: bold;', 'color: #e74c3c;', price.toLocaleString());
console.log('%cTotal spent in USD:%c $%s', 'color: #3498db; font-weight: bold;', 'color: #e74c3c;', usd.toLocaleString());
console.log('%cTotal discount:%c %s Toman', 'color: #3498db; font-weight: bold;', 'color: #2ecc71;', discount.toLocaleString());
console.log('%cOldest order date:%c %s (%d years and %d days ago)', 'color: #3498db; font-weight: bold;', 'color: #f39c12;', oldestOrderDate.toLocaleDateString('en-CA'), yearsDiff, remainingDays);
@shervintech
Copy link

For snapp.express use this snippet code:

let jwtJsonString = localStorage.getItem("JWT");
let jwt = JSON.parse(jwtJsonString).access_token;


let response = await fetch("https://api.snapp.express/mobile/v1/order/reorder?size=2000&page=0&vendorSuperType=SUPERMARKET&split_page=0&client=PWA&optionalClient=PWA&deviceType=PWA&appVersion=5.6.6&clientVersion=2.8.7&optionalVersion=5.6.6&UDID=3b778aa6-5266-4d08-a94a-074939993d13", {
  "headers": {
    "accept": "application/json, text/plain, */*",
    "accept-language": "en-US,en;q=0.9",
    "authorization": "Bearer " + jwt,
    "cache-control": "no-cache",
    "content-type": "application/x-www-form-urlencoded",
    "pragma": "no-cache",
    "sec-ch-ua": "\".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"",
    "sec-ch-ua-mobile": "?1",
    "sec-ch-ua-platform": "\"Android\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site"
  },
  "referrer": "https://m.snapp.express/",
  "referrerPolicy": "strict-origin-when-cross-origin",
  "body": null,
  "method": "GET",
  "mode": "cors",
  "credentials": "include"
});

const content = (await response.json()).data.orders;

let price = 0;
let discount = 0;
for (let i = 0; i < content.length; i++) {
    let order = content[i];
    if (!order.orderCanceled) {
        price += order['totalPrice'];
        discount += order['sumAllDiscount'];
    }
}

console.log(`Total order: ${content.length}`)
console.log(`Total spent: ${price.toLocaleString()}`);
console.log(`Total discount: ${discount.toLocaleString()}`);
console.log(`Oldest order date: ${content.at(-1).startedAt}`);

@Heshmatkhah
Copy link

راهنمای استفاده از اسکریپت:

  • تو مرورگر دسکتاپ اسنپ فود رو باز کنید (نسخه موبایلشو باز نکنید)
  • اگر لاگین نیستید، لاگین کنید.
  • بعد راست کلیک کنید و گزینه Inspect رو انتخاب کنید
  • برید تب کنسول
  • اسکریپت رو paste کنید

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