Skip to content

Commit 0d54046

Browse files
authored
Merge pull request #5 from Benevanio/fix/export-padrao-pasta-output
fix: arquivos de exportação padrão na pasta output/
2 parents b57d62c + 1c1c7f7 commit 0d54046

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ Todas sao opcionais.
187187
- `WAIT_BETWEEN_SEARCHES_MS` (padrao: `5000`)
188188
- `PAGE_TIMEOUT_MS` (padrao: `10000`)
189189
- `MAX_PAGES_PER_KEYWORD` (padrao: `5`)
190-
- `OUTPUT_FILE` (padrao: `vagas_linkedin.xlsx`)
191-
- `PDF_FILE` (padrao: `vagas_linkedin.pdf`)
190+
- `OUTPUT_FILE` (padrao: `output/vagas_linkedin.xlsx`)
191+
- `PDF_FILE` (padrao: `output/vagas_linkedin.pdf`)
192192
- `SEARCH_LOCATION` (padrao: `Brasil`)
193193
- `SEARCH_GEO_ID` (padrao: `106057199`)
194194
- `SEARCH_LANGUAGE` (padrao: `pt`)
@@ -212,10 +212,10 @@ set SEARCH_KEYWORDS=UX Designer,UI Designer,Product Manager,Product Owner&& npm
212212

213213
## Saida
214214

215-
Arquivos gerados por padrao:
215+
Arquivos gerados por padrao (pasta `output/`):
216216

217-
- `vagas_linkedin.xlsx`
218-
- `vagas_linkedin.pdf`
217+
- `output/vagas_linkedin.xlsx`
218+
- `output/vagas_linkedin.pdf`
219219

220220
Colunas exportadas:
221221

src/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export function getConfig() {
6464
width: parseNumber(process.env.VIEWPORT_WIDTH, 1280),
6565
height: parseNumber(process.env.VIEWPORT_HEIGHT, 800)
6666
},
67-
outputFile: process.env.OUTPUT_FILE || "vagas_linkedin.xlsx",
68-
pdfFile: process.env.PDF_FILE || "vagas_linkedin.pdf",
67+
outputFile: process.env.OUTPUT_FILE || "output/vagas_linkedin.xlsx",
68+
pdfFile: process.env.PDF_FILE || "output/vagas_linkedin.pdf",
6969
searchLocation: process.env.SEARCH_LOCATION || "Brasil",
7070
searchGeoId: process.env.SEARCH_GEO_ID || "106057199",
7171
searchLanguage: process.env.SEARCH_LANGUAGE || "pt",

src/exporter.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
import { createWriteStream } from "fs";
1+
import { createWriteStream, mkdirSync } from "fs";
2+
import { dirname } from "path";
23
import PDFDocument from "pdfkit";
34
import XLSX from "xlsx";
45
import { logInfo } from "./logger.js";
56

7+
function ensureParentDir(filePath) {
8+
const dir = dirname(filePath);
9+
if (dir && dir !== ".") {
10+
mkdirSync(dir, { recursive: true });
11+
}
12+
}
13+
614
export function exportToExcel(rows, outputFile) {
15+
ensureParentDir(outputFile);
716
const worksheet = XLSX.utils.json_to_sheet(rows);
817
const workbook = XLSX.utils.book_new();
918
XLSX.utils.book_append_sheet(workbook, worksheet, "Vagas");
@@ -21,6 +30,7 @@ function cleanJobUrl(url) {
2130
}
2231

2332
export function exportToPDF(rows, outputFile) {
33+
ensureParentDir(outputFile);
2434
return new Promise((resolve, reject) => {
2535
const doc = new PDFDocument({ margin: 30, size: "A4", layout: "landscape" });
2636
const stream = createWriteStream(outputFile);

0 commit comments

Comments
 (0)