feat: get variation categories automatically
This commit is contained in:
13
src/lib/server/crawler/clevertronik/data/battery.ts
Normal file
13
src/lib/server/crawler/clevertronik/data/battery.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Effect } from 'effect'
|
||||
import type { Page } from 'puppeteer'
|
||||
import { getSelected } from '.'
|
||||
import { getBatteryVariations } from '../variations/battery'
|
||||
|
||||
export const getBattery = (page: Page) =>
|
||||
Effect.gen(function* () {
|
||||
const batteryVariations = yield* getBatteryVariations(page)
|
||||
|
||||
const selectedCapacity = yield* getSelected(batteryVariations ?? [])
|
||||
|
||||
return selectedCapacity.label
|
||||
})
|
||||
@@ -9,6 +9,7 @@ import { getColor } from './color'
|
||||
import { getSim } from './sim'
|
||||
import { getStockLevel } from './stockLevel'
|
||||
import { getDevices } from './devices'
|
||||
import { getBattery } from './battery'
|
||||
|
||||
export class ExtractSelectedVariationError extends Data.TaggedError(
|
||||
'ExtractSelectedVariationError',
|
||||
@@ -49,6 +50,7 @@ export type PageData = {
|
||||
color: string
|
||||
sim: string
|
||||
stockLevel: string
|
||||
battery: string
|
||||
devices: DeviceData[]
|
||||
}
|
||||
|
||||
@@ -76,8 +78,11 @@ export const getPageData = (page: Page) =>
|
||||
const sim = yield* getSim(page)
|
||||
|
||||
const stockLevel = yield* getStockLevel(page)
|
||||
|
||||
const devices = yield* getDevices(page)
|
||||
|
||||
const battery = yield* getBattery(page)
|
||||
|
||||
const pageData: PageData = {
|
||||
price,
|
||||
productName,
|
||||
@@ -87,6 +92,7 @@ export const getPageData = (page: Page) =>
|
||||
sim,
|
||||
stockLevel,
|
||||
devices,
|
||||
battery,
|
||||
}
|
||||
|
||||
return pageData
|
||||
|
||||
Reference in New Issue
Block a user