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.
107 lines
4.6 KiB
TypeScript
107 lines
4.6 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 jobLocation = locM ? locM[1].trim() : "";
|
|
const loc = jobLocation.toLowerCase();
|
|
const isBrazil = loc.includes("brazil") || loc.includes("brasil") || loc === "" || loc.includes("remote");
|
|
const isOther = /switzerland|germany|united states|france|uk\b|netherlands/i.test(jobLocation);
|
|
if (!isBrazil || isOther) continue;
|
|
jobs.push({ id, title: clean(titleM[1]), company: companyM ? clean(companyM[1]) : "", location: jobLocation || "Remote", link: `https://www.linkedin.com/jobs/view/${id}/` });
|
|
}
|
|
return jobs;
|
|
}
|
|
|
|
// German language signal in description
|
|
const DE_LANG_RE = /\b(german|alemão|deutsch|deutschkenntnisse|german\s+language|língua\s+alem[aã])\b/i;
|
|
// Multilingual signal (3+ languages)
|
|
const MULTI_RE = /\b(trilingual|multilingual|3\s+languages|três\s+idiomas|três\s+línguas)\b/i;
|
|
|
|
async function checkLanguages(id: string): Promise<{ german: boolean; multi: boolean }> {
|
|
await Bun.sleep(400);
|
|
try {
|
|
const res = await fetch(`https://www.linkedin.com/jobs/view/${id}/`, { headers: HEADERS });
|
|
const html = await res.text();
|
|
const m = html.match(/class="show-more-less-html__markup[^"]*">([\s\S]{0,8000}?)<\/div>/);
|
|
const text = (m ? m[1] : html).replace(/<[^>]+>/g, " ");
|
|
return { german: DE_LANG_RE.test(text), multi: MULTI_RE.test(text) };
|
|
} catch {
|
|
return { german: false, multi: false };
|
|
}
|
|
}
|
|
|
|
const PAGE_SIZE = 25;
|
|
const MAX_PAGES = 4;
|
|
const baseUrl = `https://www.linkedin.com/jobs/search/?keywords=${encodeURIComponent(KEYWORDS)}&location=Brazil&f_WT=2&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} found, ${newOnPage} new`);
|
|
if (newOnPage === 0) break;
|
|
}
|
|
|
|
console.log(`\n${allJobs.length} vagas. Checando por alemão / multilíngue…\n`);
|
|
|
|
const german: Job[] = [];
|
|
const multi: Job[] = [];
|
|
|
|
for (const job of allJobs) {
|
|
process.stdout.write(` ${job.id}… `);
|
|
const { german: hasDE, multi: hasMulti } = await checkLanguages(job.id);
|
|
const flags = [hasDE && "DE", hasMulti && "MULTI"].filter(Boolean).join("+");
|
|
console.log(flags || "—");
|
|
if (hasDE) german.push(job);
|
|
if (hasMulti) multi.push(job);
|
|
}
|
|
|
|
console.log(`\n🇩🇪 ${german.length} vagas com alemão:`);
|
|
for (const j of german) console.log(` ${j.title} — ${j.company} (${j.location})\n ${j.link}`);
|
|
|
|
console.log(`\n🌐 ${multi.length} vagas multilíngue:`);
|
|
for (const j of multi) console.log(` ${j.title} — ${j.company} (${j.location})\n ${j.link}`);
|