feat(linkedin-search): add --jobage-minutes for sub-day freshness windows (#302)

jobageToTPR() only emits whole-day f_TPR windows, so a search can't be
restricted to postings from the last N minutes. LinkedIn's f_TPR filters
server-side down to one-second granularity (confirmed empirically), so
this is a pure window-construction change via a new minutesToTPR()
helper - no HTML parsing changes needed.

--jobage-minutes and --jobage both express a freshness window; passing
both is rejected with CONFLICTING_AGE_FLAGS rather than one silently
overriding the other.
This commit is contained in:
Gurnoor Kaur
2026-08-07 15:50:23 +02:00
committed by GitHub
parent a7ac6fea75
commit b167efae3b
7 changed files with 113 additions and 2 deletions
@@ -47,6 +47,7 @@ SEARCH FLAGS
"Berlin, Germany", "London, United Kingdom", or "Remote".
--query, -q <text> Keywords (job title, skill, or role). Recommended.
--jobage <days> Posted within N days: 1, 7, 14, 30. Default: all.
--jobage-minutes <n> Posted within N minutes (sub-day precision). Conflicts with --jobage.
--remote <mode> remote | hybrid | onsite. Filter by workplace type.
--page <n> 1-indexed page (10 results/page). Default 1.
--limit, -n <n> Cap results emitted (client-side).
@@ -56,6 +57,7 @@ EXAMPLES
bun run src/cli.ts search -q "data engineer" -l "Bengaluru, Karnataka, India" --jobage 30 --format table
bun run src/cli.ts search -q "product manager" -l "Berlin, Germany" --remote remote --format table
bun run src/cli.ts search -q "paralegal" -l "Remote" --format table
bun run src/cli.ts search -q "engineer" -l "Remote" --jobage-minutes 30 --format table
bun run src/cli.ts detail 4300011451 --format plain
Personal use only — uses LinkedIn's public pages; keep volume low (LinkedIn ToS).
@@ -84,6 +86,16 @@ async function main(): Promise<number> {
}
const fmt = (flags.format as string) || "json"
if (flags.jobage !== undefined && flags["jobage-minutes"] !== undefined) {
process.stderr.write(
JSON.stringify({
error: "--jobage and --jobage-minutes both set a freshness window; pass only one",
code: "CONFLICTING_AGE_FLAGS",
}) + "\n",
)
return 1
}
const parseIntFlag = (name: string, raw: string | boolean | string[]): number | null => {
const val = parseInt(raw as string, 10)
if (isNaN(val)) {
@@ -98,6 +110,18 @@ async function main(): Promise<number> {
if (v === null) return 1
flags.jobage = String(v)
}
if (flags["jobage-minutes"] !== undefined) {
const raw = flags["jobage-minutes"]
const v = parseIntFlag("jobage-minutes", raw)
if (v === null) return 1
if (v <= 0) {
process.stderr.write(
JSON.stringify({ error: `--jobage-minutes must be a positive number, got "${raw}"`, code: "BAD_ARG" }) + "\n",
)
return 1
}
flags["jobage-minutes"] = String(v)
}
if (flags.page !== undefined) {
const v = parseIntFlag("page", flags.page)
if (v === null) return 1
@@ -113,6 +137,7 @@ async function main(): Promise<number> {
query: typeof flags.query === "string" ? flags.query : undefined,
location,
jobage: flags.jobage ? parseInt(flags.jobage as string, 10) : 9999,
jobageMinutes: flags["jobage-minutes"] ? parseInt(flags["jobage-minutes"] as string, 10) : undefined,
remote: typeof flags.remote === "string" ? flags.remote : undefined,
page: flags.page ? Math.max(1, parseInt(flags.page as string, 10)) : 1,
limit: flags.limit ? parseInt(flags.limit as string, 10) : undefined,
@@ -3,6 +3,7 @@ import {
htmlFetch,
parseJobCards,
jobageToTPR,
minutesToTPR,
workTypeFlag,
writeError,
type JobCard,
@@ -12,6 +13,7 @@ export interface SearchOpts {
query?: string
location: string
jobage: number
jobageMinutes?: number
remote?: string // "remote" | "hybrid" | "onsite"
page: number
limit?: number
@@ -22,7 +24,7 @@ function buildUrl(opts: SearchOpts): string {
const params = new URLSearchParams()
if (opts.query) params.set("keywords", opts.query)
if (opts.location) params.set("location", opts.location)
const tpr = jobageToTPR(opts.jobage)
const tpr = opts.jobageMinutes !== undefined ? minutesToTPR(opts.jobageMinutes) : jobageToTPR(opts.jobage)
if (tpr) params.set("f_TPR", tpr)
const wt = workTypeFlag(opts.remote)
if (wt) params.set("f_WT", wt)
@@ -256,6 +256,12 @@ export function jobageToTPR(days: number): string | null {
return `r${days * 86400}`
}
/** Convert a job-age in minutes to LinkedIn's f_TPR seconds value (sub-day precision). */
export function minutesToTPR(minutes: number): string | null {
if (!minutes || minutes <= 0) return null
return `r${minutes * 60}`
}
/** Workplace-type flag: on-site=1, remote=2, hybrid=3. */
export function workTypeFlag(mode: string | undefined): string | null {
switch ((mode || "").toLowerCase()) {