From 38439cc6b7e480669d41cb7b609808eb978058b9 Mon Sep 17 00:00:00 2001 From: the1812 Date: Mon, 10 May 2021 13:55:17 +0800 Subject: [PATCH] Update donate history --- .gitignore | 1 + builder/node/donate-table/index.js | 53 +++++++++++++++++++++++++ builder/node/donate-table/index.ts | 49 +++++++++++++++++++++++ builder/node/donate-table/package.json | 11 +++++ builder/node/donate-table/tsconfig.json | 12 ++++++ builder/node/donate-table/yarn.lock | 8 ++++ doc/donate.md | 24 +++++++++++ 7 files changed, 158 insertions(+) create mode 100644 builder/node/donate-table/index.js create mode 100644 builder/node/donate-table/index.ts create mode 100644 builder/node/donate-table/package.json create mode 100644 builder/node/donate-table/tsconfig.json create mode 100644 builder/node/donate-table/yarn.lock diff --git a/.gitignore b/.gitignore index 6e8c38187..37ce60f32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ bilibili-evolved.dev.js .DS_Store builder/dotnet/Properties +dist/ .node_modules/ .ts-output/ .sass-output/ diff --git a/builder/node/donate-table/index.js b/builder/node/donate-table/index.js new file mode 100644 index 000000000..42bbeac63 --- /dev/null +++ b/builder/node/donate-table/index.js @@ -0,0 +1,53 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const sync_1 = __importDefault(require("csv-parse/lib/sync")); +const fs_1 = __importDefault(require("fs")); +const files = process.argv.slice(2); +const parseAliPay = (csv) => { + csv.forEach(item => { + item.sortKey = Number(new Date(item.创建时间)).toString(); + item.toString = () => { + let name = ''; + if (item.商品名称 !== '收钱码收款') { + name += item.商品名称 + ' '; + } + name += item.对方名称 + ' ' + item.付款备注; + return `| ${item.创建时间.replace(/-/g, '.')} | ${name} | ${item.支付宝交易号.substring(item.支付宝交易号.length - 4)} | ¥${item['订单金额(元)']} |`; + }; + }); + return csv; +}; +const parseWeChat = (csv) => { + csv.forEach(item => { + item.sortKey = Number(new Date(item.交易时间)).toString(); + item.toString = () => { + let name = item.交易对方; + const noteMatch = item.商品.match(/付款方留言:(.+)/); + if (noteMatch) { + name += ' ' + noteMatch[1]; + } + if (item.备注.trim() !== '/') { + name += ' ' + item.备注; + } + item.交易单号 = item.交易单号.trim(); + return `| ${item.交易时间.replace(/-/g, '.')} | ${name} | ${item.交易单号.substring(item.交易单号.length - 4)} | ${item['金额(元)']} |`; + }; + }); + return csv; +}; +const items = files.map(file => { + const text = fs_1.default.readFileSync(file, { encoding: 'utf-8' }); + const csv = sync_1.default(text, { columns: true }); + if (file.includes('支付宝')) { + return parseAliPay(csv); + } + if (file.includes('微信')) { + return parseWeChat(csv); + } + console.warn(`not parse method for ${file}`); + return []; +}).flat().sort((a, b) => parseInt(b.sortKey) - parseInt(a.sortKey)); +fs_1.default.writeFileSync('dist/output.md', items.join('\n')); diff --git a/builder/node/donate-table/index.ts b/builder/node/donate-table/index.ts new file mode 100644 index 000000000..8dbebb9c9 --- /dev/null +++ b/builder/node/donate-table/index.ts @@ -0,0 +1,49 @@ +import parse from 'csv-parse/lib/sync' +import fs from 'fs' + +const files = process.argv.slice(2) +const parseAliPay = (csv: Record[]) => { + csv.forEach(item => { + item.sortKey = Number(new Date(item.创建时间)).toString() + item.toString = () => { + let name = '' + if (item.商品名称 !== '收钱码收款') { + name += item.商品名称 + ' ' + } + name += item.对方名称 + ' ' + item.付款备注 + return `| ${item.创建时间.replace(/-/g, '.')} | ${name} | ${item.支付宝交易号.substring(item.支付宝交易号.length - 4)} | ¥${item['订单金额(元)']} |` + } + }) + return csv +} +const parseWeChat = (csv: Record[]) => { + csv.forEach(item => { + item.sortKey = Number(new Date(item.交易时间)).toString() + item.toString = () => { + let name = item.交易对方 + const noteMatch = item.商品.match(/付款方留言:(.+)/) + if (noteMatch) { + name += ' ' + noteMatch[1] + } + if (item.备注.trim() !== '/') { + name += ' ' + item.备注 + } + item.交易单号 = item.交易单号.trim() + return `| ${item.交易时间.replace(/-/g, '.')} | ${name} | ${item.交易单号.substring(item.交易单号.length - 4)} | ${item['金额(元)']} |` + } + }) + return csv +} +const items = files.map(file => { + const text = fs.readFileSync(file, { encoding: 'utf-8' }) + const csv = parse(text, { columns: true }) + if (file.includes('支付宝')) { + return parseAliPay(csv) + } + if (file.includes('微信')) { + return parseWeChat(csv) + } + console.warn(`not parse method for ${file}`) + return [] +}).flat().sort((a, b) => parseInt(b.sortKey) - parseInt(a.sortKey)) +fs.writeFileSync('dist/output.md', items.join('\n')) diff --git a/builder/node/donate-table/package.json b/builder/node/donate-table/package.json new file mode 100644 index 000000000..eca85d4ef --- /dev/null +++ b/builder/node/donate-table/package.json @@ -0,0 +1,11 @@ +{ + "name": "donate-table", + "version": "1.0.0", + "main": "index.js", + "author": "Grant Howard", + "license": "MIT", + "private": true, + "dependencies": { + "csv-parse": "^4.15.4" + } +} diff --git a/builder/node/donate-table/tsconfig.json b/builder/node/donate-table/tsconfig.json new file mode 100644 index 000000000..2c481ce4e --- /dev/null +++ b/builder/node/donate-table/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ESNext", + "esModuleInterop": true, + "module": "commonjs", + "strict": true, + "sourceMap": false, + }, + "include": [ + "index.ts" + ] +} diff --git a/builder/node/donate-table/yarn.lock b/builder/node/donate-table/yarn.lock new file mode 100644 index 000000000..5ea5956d4 --- /dev/null +++ b/builder/node/donate-table/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +csv-parse@^4.15.4: + version "4.15.4" + resolved "https://registry.npm.taobao.org/csv-parse/download/csv-parse-4.15.4.tgz#ad1ec62aaf71a642982dfcb81f1848184d691db5" + integrity sha1-rR7GKq9xpkKYLfy4HxhIGE1pHbU= diff --git a/doc/donate.md b/doc/donate.md index 93d64e872..ff7a6460f 100644 --- a/doc/donate.md +++ b/doc/donate.md @@ -19,6 +19,30 @@ | 时间 | 用户名 | 单号后4位 | 金额 | | ------------------- | ------------ | --------- | ------ | +| 2021.05.10 09:36:30 | *白 | 1262 | ¥10.00 | +| 2021.05.09 00:59:51 | *我 | 3264 | ¥20.00 | +| 2021.05.07 23:07:16 | *宜 | 0225 | ¥0.29 | +| 2021.05.07 10:20:08 | s*e | 6521 | ¥6.66 | +| 2021.05.04 11:47:01 | *大 | 7776 | ¥12.00 | +| 2021.05.04 00:22:20 | *子 | 7618 | ¥2.00 | +| 2021.05.02 18:16:59 | *七 | 7749 | ¥2.00 | +| 2021.04.30 10:20:54 | 乔* | 0271 | ¥5.00 | +| 2021.04.29 15:28:10 | *文 | 7229 | ¥5.00 | +| 2021.04.28 22:40:07 | *数 | 0272 | ¥1.00 | +| 2021.04.26 23:45:27 | x*y | 6638 | ¥5.00 | +| 2021.04.25 08:16:12 | *陸 | 9503 | ¥30.00 | +| 2021.04.23 13:39:53 | *楠 | 7296 | ¥5.00 | +| 2021.04.22 12:10:02 | *安 | 1136 | ¥12.00 | +| 2021.04.22 08:22:04 | M*z | 5584 | ¥5.00 | +| 2021.04.20 18:48:24 | 青* | 1619 | ¥5.00 | +| 2021.04.18 14:31:56 | mr.Donation | 6392 | ¥6.66 | +| 2021.04.15 18:40:10 | 匿名 | 4622 | ¥5.00 | +| 2021.04.12 14:08:37 | 卷发哥斯拉 | 0684 | ¥66.00 | +| 2021.04.11 15:22:57 | *杰 | 8609 | ¥0.66 | +| 2021.04.07 00:58:23 | 匿名 | 9622 | ¥10.00 | +| 2021.04.06 11:35:03 | *辰 | 5187 | ¥5.00 | +| 2021.04.05 20:43:18 | A*N | 2592 | ¥15.00 | +| 2021.04.05 20:36:31 | A*N | 1506 | ¥1.00 | | 2021.03.30 20:17:18 | *雨 | 3243 | ¥5.00 | | 2021.03.27 09:09:47 | *俊 | 0097 | ¥1.00 | | 2021.03.27 00:06:09 | *斌 | 1363 | ¥5.00 |