From 8fd0d779eaf21ee0f8441fa7a31a18bee03ce590 Mon Sep 17 00:00:00 2001 From: Faker <Faker@apple.com> Date: Tue, 25 Oct 2022 01:05:46 +0800 Subject: [PATCH] Delete jd_bean_aggregation.cjs --- jd_bean_aggregation.cjs | 89 ----------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 jd_bean_aggregation.cjs diff --git a/jd_bean_aggregation.cjs b/jd_bean_aggregation.cjs deleted file mode 100644 index 6ae54b0..0000000 --- a/jd_bean_aggregation.cjs +++ /dev/null @@ -1,89 +0,0 @@ -/** - * select name, bean from bean_change where date=today and amount > 0 group by name order by amount desc - */ - -const {JDHelloWorld} = require("./TS_JDHelloWorld") -const {getDate} = require("date-fns"); -const ConsoleGrid = require("console-grid"); - -class Aggregate_Bean extends JDHelloWorld { - constructor() { - super(); - } - - async init() { - await this.run(new Aggregate_Bean()) - } - - async main(user) { - let p = 1, arr = [], aggregation = {}, flag = true, sum = 0, len = 0 - while (p && flag) { - try { - let res = await this.post('https://api.m.jd.com/client.action?functionId=getJingBeanBalanceDetail', - `body=${encodeURIComponent(JSON.stringify({"pageSize": "20", "page": p.toString()}))}&appid=ld`, { - 'Host': 'api.m.jd.com', - 'Content-Type': 'application/x-www-form-urlencoded', - 'User-Agent': "jdapp;iPhone;9.4.4;14.3;network/4g;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", - 'Cookie': user.cookie, - }) - let today = getDate(new Date()) - // console.log(p, res['detailList'].length) - for (let t of res['detailList']) { - let amount = parseInt(t.amount), date = getDate(new Date(t.date)) - if (date !== today) { - flag = false - break - } - if (amount > 0) { - sum += amount - t['eventMassage'].length > len ? len = t['eventMassage'].length : null - if (t['eventMassage'] in aggregation) { - aggregation[t['eventMassage']] += amount - } else { - aggregation[t['eventMassage']] = amount - } - } - } - await this.wait(2000) - if (p < 20) { - p++ - } else { - break - } - } catch (e) { - console.log('error', e) - await this.wait(2000) - break - } - } - for (let k in aggregation) { - arr.push({ - 'name': k, - 'amount': aggregation[k] - }) - } - arr.sort((a, b) => { - return b.amount - a.amount - }) - arr = [...arr, {name: '合计', amount: sum}] - const consoleGrid = new ConsoleGrid(); - const data = { - columns: [{ - id: "name", - name: `Name`, - type: "string", - maxWidth: len * 2 + 3, - }, { - id: "amount", - type: "number", - name: "Amount", - minWidth: 5, - align: "right" - }], - rows: arr - }; - consoleGrid.render(data); - } -} - -new Aggregate_Bean().init().then()