Skip to content

Commit

Permalink
Update donate history
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed May 10, 2021
1 parent c742bc6 commit 38439cc
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
bilibili-evolved.dev.js
.DS_Store
builder/dotnet/Properties
dist/
.node_modules/
.ts-output/
.sass-output/
Expand Down
53 changes: 53 additions & 0 deletions 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'));
49 changes: 49 additions & 0 deletions 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<string, string>[]) => {
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<string, string>[]) => {
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'))
11 changes: 11 additions & 0 deletions 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"
}
}
12 changes: 12 additions & 0 deletions builder/node/donate-table/tsconfig.json
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ESNext",
"esModuleInterop": true,
"module": "commonjs",
"strict": true,
"sourceMap": false,
},
"include": [
"index.ts"
]
}
8 changes: 8 additions & 0 deletions 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=
24 changes: 24 additions & 0 deletions doc/donate.md
Expand Up @@ -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 |
Expand Down

0 comments on commit 38439cc

Please sign in to comment.