Adds the one-off scripts accumulated across recent sessions, removes temp scripts whose searches now live in config.ts as role-family sweeps, and updates fetch-other.ts plus the LinkedIn post drafts.
81 lines
3.1 KiB
TypeScript
81 lines
3.1 KiB
TypeScript
import { KEYWORDS } from "../config.ts";
|
|
import { JUNIOR_TITLE_RE, JAVA_TITLE_RE, SOFTWARE_TITLE_RE } from "../fetch.ts";
|
|
|
|
const HEADERS = {
|
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
|
|
"Accept-Language": "en-US,en;q=0.9",
|
|
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
};
|
|
|
|
function clean(raw: string): string {
|
|
return raw
|
|
.replace(/<[^>]+>/g, "")
|
|
.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">")
|
|
.replace(/"/g, '"').replace(/'/g, "'")
|
|
.replace(/\s+/g, " ").trim();
|
|
}
|
|
|
|
interface Job { id: string; title: string; company: string; location: string; link: string; }
|
|
|
|
function parseJobs(html: string): Job[] {
|
|
const jobs: Job[] = [];
|
|
const idRe = /data-entity-urn="urn:li:jobPosting:(\d+)"/g;
|
|
const positions: { id: string; start: number }[] = [];
|
|
let m;
|
|
while ((m = idRe.exec(html)) !== null) positions.push({ id: m[1], start: m.index });
|
|
|
|
for (let i = 0; i < positions.length; i++) {
|
|
const { id, start } = positions[i];
|
|
const card = html.slice(start, Math.min(positions[i + 1]?.start ?? Infinity, start + 3000));
|
|
const titleM = card.match(/<h3 class="base-search-card__title">\s*([\s\S]*?)\s*<\/h3>/);
|
|
if (!titleM) continue;
|
|
const companyM = card.match(/<h4 class="base-search-card__subtitle">[\s\S]{0,300}?<a[^>]*>\s*([\s\S]*?)\s*<\/a>/);
|
|
const locM = card.match(/job-search-card__location[^>]*>\s*([^<]+)/);
|
|
const company = companyM ? clean(companyM[1]) : "";
|
|
|
|
// Only Stone (exact or known variants)
|
|
if (!/^stone(\s+co\.?|\s+pagamentos)?$/i.test(company.trim())) continue;
|
|
|
|
jobs.push({
|
|
id, title: clean(titleM[1]), company,
|
|
location: locM ? locM[1].trim() : "Brazil",
|
|
link: `https://www.linkedin.com/jobs/view/${id}/`,
|
|
});
|
|
}
|
|
return jobs;
|
|
}
|
|
|
|
const PAGE_SIZE = 25;
|
|
const MAX_PAGES = 6;
|
|
// No work type filter — include onsite/hybrid too since it's a target company
|
|
const baseUrl = `https://www.linkedin.com/jobs/search/?keywords=${encodeURIComponent(KEYWORDS)}&location=Brazil&f_TPR=r2592000`;
|
|
|
|
const allJobs: Job[] = [];
|
|
const seen = new Set<string>();
|
|
|
|
for (let page = 0; page < MAX_PAGES; page++) {
|
|
if (page > 0) await Bun.sleep(500);
|
|
const url = `${baseUrl}&start=${page * PAGE_SIZE}`;
|
|
process.stdout.write(` page ${page + 1} … `);
|
|
const res = await fetch(url, { headers: HEADERS });
|
|
if (!res.ok) { console.error(`failed (${res.status})`); break; }
|
|
const html = await res.text();
|
|
const jobs = parseJobs(html)
|
|
.filter((j) => !JUNIOR_TITLE_RE.test(j.title))
|
|
.filter((j) => !JAVA_TITLE_RE.test(j.title))
|
|
.filter((j) => SOFTWARE_TITLE_RE.test(j.title));
|
|
|
|
let newOnPage = 0;
|
|
for (const job of jobs) {
|
|
if (!seen.has(job.id)) { seen.add(job.id); allJobs.push(job); newOnPage++; }
|
|
}
|
|
console.log(`${jobs.length} Stone jobs, ${newOnPage} new`);
|
|
if (newOnPage === 0) break;
|
|
}
|
|
|
|
console.log(`\nTotal: ${allJobs.length} vagas na Stone\n`);
|
|
for (const j of allJobs) {
|
|
console.log(`${j.title} — ${j.company} (${j.location})`);
|
|
console.log(` ${j.link}`);
|
|
}
|