gccollect
12 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
13 additions and
6 deletions
-
apps/api/src/services/data-provider/manual/manual.service.ts
-
apps/api/src/services/symbol-profile/symbol-profile.service.ts
-
libs/common/src/lib/interfaces/scraper-configuration.interface.ts
|
|
@ -257,13 +257,15 @@ export class ManualService implements DataProviderInterface { |
|
|
|
signal: abortController.signal |
|
|
|
}); |
|
|
|
|
|
|
|
let factor = isNaN(+scraperConfiguration.postprocessor) |
|
|
|
? 1.0 |
|
|
|
: +scraperConfiguration.postprocessor; |
|
|
|
if (headers['content-type'].includes('application/json')) { |
|
|
|
const data = JSON.parse(body); |
|
|
|
const value = String( |
|
|
|
jsonpath.query(data, scraperConfiguration.selector)[0] |
|
|
|
); |
|
|
|
|
|
|
|
return extractNumberFromString({ locale, value }); |
|
|
|
return factor * extractNumberFromString({ locale, value }); |
|
|
|
} else { |
|
|
|
const $ = cheerio.load(body); |
|
|
|
|
|
|
@ -273,10 +275,13 @@ export class ManualService implements DataProviderInterface { |
|
|
|
} catch {} |
|
|
|
} |
|
|
|
|
|
|
|
return extractNumberFromString({ |
|
|
|
locale, |
|
|
|
value: $(scraperConfiguration.selector).first().text() |
|
|
|
}); |
|
|
|
return ( |
|
|
|
factor * |
|
|
|
extractNumberFromString({ |
|
|
|
locale, |
|
|
|
value: $(scraperConfiguration.selector).first().text() |
|
|
|
}) |
|
|
|
); |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
throw error; |
|
|
|
|
|
@ -275,6 +275,7 @@ export class SymbolProfileService { |
|
|
|
headers: |
|
|
|
scraperConfiguration.headers as ScraperConfiguration['headers'], |
|
|
|
locale: scraperConfiguration.locale as string, |
|
|
|
postprocessor: scraperConfiguration.postprocessor as string, |
|
|
|
selector: scraperConfiguration.selector as string, |
|
|
|
url: scraperConfiguration.url as string |
|
|
|
}; |
|
|
|
|
|
@ -2,6 +2,7 @@ export interface ScraperConfiguration { |
|
|
|
defaultMarketPrice?: number; |
|
|
|
headers?: { [key: string]: string }; |
|
|
|
locale?: string; |
|
|
|
postprocessor?: string; |
|
|
|
selector: string; |
|
|
|
url: string; |
|
|
|
} |
|
|
|