Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
bilibili-evolved.dev.js | ||
.DS_Store | ||
builder/dotnet/Properties | ||
dist/ | ||
.node_modules/ | ||
.ts-output/ | ||
.sass-output/ | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"esModuleInterop": true, | ||
"module": "commonjs", | ||
"strict": true, | ||
"sourceMap": false, | ||
}, | ||
"include": [ | ||
"index.ts" | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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= |
This file contains 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