B:BD[
3.10999] → [
3.10999:11038]
cliProgressBar.update(++progress);
let [producer, brand, name, join_name, hack] = normalize(
products[idx][0].Brand,
products[idx][0].DisplayName,
type,
await p.$eval('.sku-lp', e => e.textContent.trim())
);
let blend = false;
if(products[idx][0].Type === 'Blend') {
blend = true;
let fuck = products[idx][0].Strain.match(/hybrid|indica|sativa/i)?.[0]?.toLowerCase();
if(fuck) {
products[idx][0].Type = fuck;
} else {
products[idx][0].Type = 'hybrid';
//console.log('shame', products[idx][0].Link);
//cliProgressBar.update(++progress);
//continue;
}
}
if(/blend/i.test(products[idx][0].Strain)) {
blend = true;
}
let terpenes = await p.$$eval('.item-terpene > h3', els => {
for(let j = els.length - 1; j >= 0; --j) {
els[j] = els[j].textContent;
if(els[j] === 'Other Terpenes') {
els.splice(j, 1);
} else {
els[j] = els[j].replace(/(\d*\.?\d+)([-−](\d*\.?\d+))?\s*([A-Za-z%]+)/, '').replace(/\s*\(.*\)\s*/, '').trim();
}
}
return els;
});
try {
terpenes.append((await p.$eval('#otherTerpenesInfoTip', el => el.textContent)).split(';'));
} catch(e) {}
let productID = (await postgres.query(`select ios_product_id($1, $2, $3, $4, $5, $6, $7, $8, $9, true, $10, $11)`, [
producer,
brand,
name,
join_name,
type,
products[idx][0].Type.toLowerCase(),
blend,
blend ? null : strain_clean(products[idx][0].Strain),
await p.$eval('.description', e => e.textContent.trim()),
terpenes,
brand === 'dosist' ? '.00225' : null
])).rows[0].ios_product_id;
for(let j = 0; j < products[idx].length; ++j) {
let portions = 1;
let quantity = products[idx][j].Quantity;
if(type === 'preroll' || type === 'capsule') {
gas.push(await p.$eval('#' + products[idx][j].VariantId, e => JSON.parse(e.dataset.variantData).disambiguatingdescription));
[,portions, quantity] = (await p.$eval('#' + products[idx][j].VariantId, e => JSON.parse(e.dataset.variantData).disambiguatingdescription)).match(quantityregex) ?? [];
portions = portions ?? 1;
if(!quantity) {
quantity = products[idx][j].Quantity
}
}
let params = [productID, portions, quantity];
let [variantID, g] = (await postgres.query(
`select ios_variant_id($1, $2, $3${type === 'oil' || type === 'spray' || type === 'capsule' ? `, _gram_equivalency => $${params.push(await p.$eval('#' + products[idx][j].VariantId, e => JSON.parse(e.dataset.variantData).equivalency))}` : ''})`,
params
)).rows[0].ios_variant_id.slice(1, -1).split(',');
//warning gram equivalency does not match
try {
let [,minTHC, maxTHC] = products[idx][j].Thc.match(range);
let [,minCBD, maxCBD] = products[idx][j].Cbd.match(range);
await postgres.query(
`insert into menu_item (
variant_id,
store_id,
cbd,
thc,
price,
stock,
path
) values (
$1,
$2,
$3,
$4,
$5,
$6,
$7
) on conflict (variant_id, store_id) do update set cbd = excluded.cbd, thc = excluded.thc, price = excluded.price, stock = excluded.stock`,
[
variantID,
storeID,
`[${minCBD ?? maxCBD ?? 0},${maxCBD ?? minCBD ?? 0}]`,
`[${minTHC ?? maxTHC ?? 0},${maxTHC ?? minTHC ?? 0}]`,
products[idx][j].AdjustedPrice.replace('$', '').split(/\s+/)[0],
await p.$eval('[data-variantId="' + products[idx][j].VariantId + '"]', el => el.getAttribute('data-count')),
products[idx][j].Link
]
);
} catch(e) {
console.log(products[idx][j]);
console.log( `[${minCBD},${maxCBD}]`,
`[${minTHC},${maxTHC}]`,
products[idx][j].AdjustedPrice.replace('$', '').split(/\s+/)[0],
await p.$eval('[data-variantId="' + products[idx][j].VariantId + '"]', el => el.getAttribute('data-count')),
products[idx][j].Link);
}
}
//cliProgressBar.update(++progress);
++progress;