Skip to content

Commit 7f710e9

Browse files
committed
feat: update format
1 parent 8655d8e commit 7f710e9

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

csv/csv.service.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import Papa from "papaparse";
22

33
export const writeCSV = async (data: any[], filename: string) => {
4-
const csv = Papa.unparse(data, {
5-
header: true,
6-
delimiter: "|",
7-
});
4+
const csv = Papa.unparse(
5+
data.map((v) => {
6+
Object.keys(v).forEach((key) => {
7+
if (typeof v[key] === "object" || Array.isArray(v[key])) {
8+
v[key] = JSON.stringify(v[key]);
9+
}
10+
});
11+
return v;
12+
}),
13+
{
14+
header: true,
15+
delimiter: "|",
16+
}
17+
);
818

919
await Bun.write(filename, csv, { createPath: true });
10-
};
20+
};

scraping/myhora.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
import { ThaiTime } from "../utils/thai-time";
88
import pLimit from "p-limit";
99

10-
const limit = pLimit(10);
10+
const limit = pLimit(20);
1111
function normalizeSpaces(str: string) {
1212
return str.replace(/\s+/g, " ").trim();
1313
}

script.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ for (const { date, ...data } of list) {
7979
}
8080

8181
for (const key in dataCSV2) {
82+
const jsonData = [...dataCSV2[key]];
8283
await writeCSV(dataCSV2[key], `./data/result/${key}.csv`);
83-
await Bun.write(`./data/result/${key}.json`, JSON.stringify(dataCSV2[key]), {
84+
await Bun.write(`./data/result/${key}.json`, JSON.stringify(jsonData), {
8485
createPath: true,
8586
});
8687
}

0 commit comments

Comments
 (0)