feat: get variation categories automatically

This commit is contained in:
Tobias Klemp
2025-11-05 20:08:26 +01:00
parent e7bd070b3e
commit c829f9f57b
6 changed files with 137 additions and 40 deletions

View 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
})

View File

@@ -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