fix: preserve default scraper result contracts
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { parseHTML } from "linkedom";
|
||||
import type { UnstableListingModeOptions } from "../types/common";
|
||||
import type {
|
||||
UnstableListingBuckets,
|
||||
UnstableListingModeOptions,
|
||||
} from "../types/common";
|
||||
import { classifyUnstableListings } from "../utils/unstable";
|
||||
import {
|
||||
type CookieConfig,
|
||||
@@ -352,6 +355,34 @@ async function loadEbayCookies(): Promise<string | undefined> {
|
||||
|
||||
// ----------------------------- Main -----------------------------
|
||||
|
||||
export default async function fetchEbayItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND?: number,
|
||||
opts?: {
|
||||
minPrice?: number;
|
||||
maxPrice?: number;
|
||||
strictMode?: boolean;
|
||||
exclusions?: string[];
|
||||
keywords?: string[];
|
||||
buyItNowOnly?: boolean;
|
||||
canadaOnly?: boolean;
|
||||
},
|
||||
unstableMode?: UnstableListingModeOptions,
|
||||
): Promise<EbayListingDetails[]>;
|
||||
export default async function fetchEbayItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND: number | undefined,
|
||||
opts: {
|
||||
minPrice?: number;
|
||||
maxPrice?: number;
|
||||
strictMode?: boolean;
|
||||
exclusions?: string[];
|
||||
keywords?: string[];
|
||||
buyItNowOnly?: boolean;
|
||||
canadaOnly?: boolean;
|
||||
} | undefined,
|
||||
unstableMode: { hideUnstableResults: true },
|
||||
): Promise<UnstableListingBuckets<EbayListingDetails>>;
|
||||
export default async function fetchEbayItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND = 1,
|
||||
@@ -366,7 +397,9 @@ export default async function fetchEbayItems(
|
||||
} = {},
|
||||
unstableMode: UnstableListingModeOptions = {},
|
||||
) {
|
||||
const finalizeResults = (listings: EbayListingDetails[]) => {
|
||||
const finalizeResults = (
|
||||
listings: EbayListingDetails[],
|
||||
): EbayListingDetails[] | UnstableListingBuckets<EbayListingDetails> => {
|
||||
if (!unstableMode.hideUnstableResults) {
|
||||
return listings;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import cliProgress from "cli-progress";
|
||||
import { parseHTML } from "linkedom";
|
||||
import type { HTMLString, UnstableListingModeOptions } from "../types/common";
|
||||
import type {
|
||||
HTMLString,
|
||||
UnstableListingBuckets,
|
||||
UnstableListingModeOptions,
|
||||
} from "../types/common";
|
||||
import { classifyUnstableListings } from "../utils/unstable";
|
||||
import {
|
||||
type Cookie,
|
||||
@@ -1061,6 +1065,20 @@ export function parseFacebookItem(
|
||||
|
||||
// ----------------------------- Main -----------------------------
|
||||
|
||||
export default async function fetchFacebookItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND?: number,
|
||||
LOCATION?: string,
|
||||
MAX_ITEMS?: number,
|
||||
unstableMode?: UnstableListingModeOptions,
|
||||
): Promise<FacebookListingDetails[]>;
|
||||
export default async function fetchFacebookItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND: number | undefined,
|
||||
LOCATION: string | undefined,
|
||||
MAX_ITEMS: number | undefined,
|
||||
unstableMode: { hideUnstableResults: true },
|
||||
): Promise<UnstableListingBuckets<FacebookListingDetails>>;
|
||||
export default async function fetchFacebookItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND = 1,
|
||||
@@ -1068,16 +1086,14 @@ export default async function fetchFacebookItems(
|
||||
MAX_ITEMS = 25,
|
||||
unstableMode: UnstableListingModeOptions = {},
|
||||
) {
|
||||
const finalizeResults = (listings: FacebookListingDetails[]) => {
|
||||
const finalizeResults = (
|
||||
listings: FacebookListingDetails[],
|
||||
): FacebookListingDetails[] | UnstableListingBuckets<FacebookListingDetails> => {
|
||||
if (!unstableMode.hideUnstableResults) {
|
||||
return listings.slice(0, MAX_ITEMS);
|
||||
}
|
||||
|
||||
const classified = classifyUnstableListings(listings);
|
||||
return {
|
||||
results: classified.results.slice(0, MAX_ITEMS),
|
||||
unstableResults: classified.unstableResults,
|
||||
};
|
||||
return classifyUnstableListings(listings.slice(0, MAX_ITEMS));
|
||||
};
|
||||
|
||||
const cookies = await ensureFacebookCookies();
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import cliProgress from "cli-progress";
|
||||
import { parseHTML } from "linkedom";
|
||||
import unidecode from "unidecode";
|
||||
import type { HTMLString, UnstableListingModeOptions } from "../types/common";
|
||||
import type {
|
||||
HTMLString,
|
||||
UnstableListingBuckets,
|
||||
UnstableListingModeOptions,
|
||||
} from "../types/common";
|
||||
import { classifyUnstableListings } from "../utils/unstable";
|
||||
import {
|
||||
type CookieConfig,
|
||||
@@ -697,6 +701,22 @@ export async function parseDetailedListing(
|
||||
|
||||
// ----------------------------- Main -----------------------------
|
||||
|
||||
export default async function fetchKijijiItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND?: number,
|
||||
BASE_URL?: string,
|
||||
searchOptions?: SearchOptions,
|
||||
listingOptions?: ListingFetchOptions,
|
||||
unstableMode?: UnstableListingModeOptions,
|
||||
): Promise<DetailedListing[]>;
|
||||
export default async function fetchKijijiItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND: number | undefined,
|
||||
BASE_URL: string | undefined,
|
||||
searchOptions: SearchOptions | undefined,
|
||||
listingOptions: ListingFetchOptions | undefined,
|
||||
unstableMode: { hideUnstableResults: true },
|
||||
): Promise<UnstableListingBuckets<DetailedListing>>;
|
||||
export default async function fetchKijijiItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND = 1,
|
||||
@@ -705,7 +725,9 @@ export default async function fetchKijijiItems(
|
||||
listingOptions: ListingFetchOptions = {},
|
||||
unstableMode: UnstableListingModeOptions = {},
|
||||
) {
|
||||
const finalizeResults = (listings: DetailedListing[]) => {
|
||||
const finalizeResults = (
|
||||
listings: DetailedListing[],
|
||||
): DetailedListing[] | UnstableListingBuckets<DetailedListing> => {
|
||||
if (!unstableMode.hideUnstableResults) {
|
||||
return listings;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user