mirror of
https://github.com/prdlk/jobyssey.git
synced 2026-11-02 13:12:49 +00:00
feat: add skills
This commit is contained in:
1 parent
6984212b17
commit
c50aa92862
150 files changed
+12702
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { DETAIL_URL, htmlFetch, parseJobDetail, writeError } from "../helpers.js"
|
||||
|
||||
export interface DetailOpts {
|
||||
id: string
|
||||
format: "json" | "plain"
|
||||
}
|
||||
|
||||
/** Accept a raw job ID, a job-view URL, or a job URN. */
|
||||
function normalizeId(input: string): string | null {
|
||||
const urn = input.match(/urn:li:jobPosting:(\d+)/)
|
||||
if (urn) return urn[1]
|
||||
const url = input.match(/-(\d{6,})(?:\?|$)/) || input.match(/\/(\d{6,})(?:\?|$)/)
|
||||
if (url) return url[1]
|
||||
const bare = input.match(/^\d{6,}$/)
|
||||
if (bare) return input
|
||||
return null
|
||||
}
|
||||
|
||||
export async function runDetail(opts: DetailOpts): Promise<number> {
|
||||
const id = normalizeId(opts.id)
|
||||
if (!id) {
|
||||
writeError(`Could not parse a job ID from "${opts.id}"`, "BAD_ID")
|
||||
return 1
|
||||
}
|
||||
try {
|
||||
const html = await htmlFetch(`${DETAIL_URL}/${id}`)
|
||||
if (!html) {
|
||||
writeError("Job not found", "NOT_FOUND")
|
||||
return 1
|
||||
}
|
||||
const job = parseJobDetail(html, id)
|
||||
|
||||
if (opts.format === "plain") {
|
||||
const lines = [
|
||||
job.title,
|
||||
`${job.company || "—"} · ${job.location || "—"}`,
|
||||
"",
|
||||
job.seniority ? `Seniority: ${job.seniority}` : "",
|
||||
job.employmentType ? `Employment: ${job.employmentType}` : "",
|
||||
job.jobFunction ? `Function: ${job.jobFunction}` : "",
|
||||
job.industries ? `Industries: ${job.industries}` : "",
|
||||
"",
|
||||
job.description || "(no description)",
|
||||
"",
|
||||
`URL: ${job.url}`,
|
||||
].filter((l) => l !== "")
|
||||
process.stdout.write(lines.join("\n") + "\n")
|
||||
} else {
|
||||
process.stdout.write(JSON.stringify(job, null, 2) + "\n")
|
||||
}
|
||||
return 0
|
||||
} catch (e) {
|
||||
writeError(e instanceof Error ? e.message : String(e), "DETAIL_FAILED")
|
||||
return 1
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user