Files
ObsidianHome/小鱼/.cdp/extract.mjs
T
2026-11-05 15:16:24 +08:00

55 lines
2.3 KiB
JavaScript

// 聚焦提取:每个 mtop 响应的日期范围 + 关键指标 + 结构
import fs from 'node:fs';
import path from 'node:path';
const dir = path.resolve(process.argv[2] || '.cdp/out/api');
const files = fs.readdirSync(dir).filter(f => f.endsWith('.txt')).sort();
const load = (f) => {
const raw = fs.readFileSync(path.join(dir, f), 'utf8');
const i = raw.indexOf('\n\n');
const url = raw.slice(5, i).trim();
let body = raw.slice(i + 2).trim();
let json = null;
try { json = JSON.parse(body); } catch {
const m = body.match(/^[^(]*\((.*)\)[;\s]*$/s);
if (m) { try { json = JSON.parse(m[1]); } catch {} }
}
return { url, json, api: (url.match(/datacompass\.[A-Za-z0-9._]+/) || [''])[0] };
};
console.log('### 各接口的 realDateRange');
for (const f of files) {
const { json, api } = load(f);
const rr = json?.extendInfo?.realDateRange;
const cyc = json?.data?.payOrdCnt?.cycle || json?.data?.itemExpCnt?.cycle || '';
console.log(`${f.padEnd(12)} ${api.replace('datacompass.', '').padEnd(38)} range=${JSON.stringify(rr)} cycle=${cyc}`);
}
const show = (f, label) => {
const { json } = load(f);
console.log('\n### ' + label + ' (' + f + ')');
const d = json?.data;
if (!d) { console.log(' no data; keys=' + JSON.stringify(Object.keys(json || {}))); return; }
if (Array.isArray(d)) { console.log(' array len=' + d.length + ' sample=' + JSON.stringify(d[0]).slice(0, 400)); return; }
for (const k of Object.keys(d)) {
const v = d[k];
if (v && typeof v === 'object' && !Array.isArray(v) && 'dataStr' in v) {
console.log(` ${k.padEnd(24)} now=${String(v.dataStr).padEnd(12)} prev=${String(v.lastDataStr).padEnd(12)} Δ=${String(v.ratioFormat).padEnd(10)} cycle=${v.cycle}`);
} else if (Array.isArray(v)) {
console.log(` ${k}[] len=${v.length} first=${JSON.stringify(v[0]).slice(0, 500)}`);
} else if (v && typeof v === 'object') {
console.log(` ${k} {} keys=${JSON.stringify(Object.keys(v)).slice(0, 300)}`);
} else {
console.log(` ${k} = ${JSON.stringify(v)}`);
}
}
};
show('30d-08.txt', 'seller.summary 近30天');
show('7d-02.txt', 'seller.summary 近7天');
show('30d-07.txt', 'item.summary 近30天');
show('30d-10.txt', 'flow.detail 近30天');
show('30d-06.txt', 'repurchase.summary 近30天');
show('30d-09.txt', 'refund.summary 近30天');