Commande

Détails de livraison

Votre commande

Votre commande

Produit Sous-total
Baseus Let''s go Slip Cover Waterproof Bag Gris+Jaune  × 1 199 DH
Sous-total 199 DH
Expédition
Total 218 DH
    import gsmarena from "./gsmarena-api/index.js"; import WooCommerceRestApi from "@woocommerce/woocommerce-rest-api"; import urlExist from "url-exist"; import { WordPress } from "./src/wordpress.js"; import { dirname } from "path"; import { fileURLToPath } from "url"; import downloadImage from "image-downloader"; import Jimp from "jimp"; import * as fsExtra from "fs-extra"; import * as fs from "fs"; import mainSitemap from "./sitemap.js"; $locale = 'en_US.UTF-8'; setlocale(LC_ALL, $locale); putenv('LC_ALL='.$locale); process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; process.env["CURLOPT_SSL_VERIFYHOST"] = 0; process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; const fromReleaseDate = new Date(1900, 1); const minWidthImage = 750; const maxHeightImage = 684; const wooCommerceRestApi = WooCommerceRestApi.default; let savedDevices = []; const brands = [ "apple-phones-48", "xiaomi-phones-80", "itel-phones-131", "infinix-phones-119", "tecno-phones-120", "vivo-phones-98", "realme-phones-118", "honor-phones-121", "oppo-phones-82", "oneplus-phones-95", "samsung-phones-9", "huawei-phones-58", "google-phones-107", "sony-phones-7", "nokia-phones-1", "nothing-phones-128", "wiko-phones-96", "lenovo-phones-73", "motorola-phones-4", "lg-phones-20", "lenovo-phones-73", "asus-phones-46", "alcatel-phones-5", "zte-phones-62", "meizu-phones-74", "blackberry-phones-36", "panasonic-phones-6", "htc-phones-45", "fairphone-phones-127", "tcl-phones-123" ]; const devicesSyncAlone = []; const WooCommerce = new wooCommerceRestApi({ url: "https://gsm.ma", consumerKey: "ck_039c5115906bd6409517805d27a975f09f411308", consumerSecret: "cs_428fb4d5495577f6ac774e7dee740ab775dbb687", version: "wc/v3", }); const wp = new WordPress({ url: "https://gsm.ma", username: "errouissimusta@gmail.com", password: "GxcO SRPw 9kty gFh0 6dv8 TSOI", }); String.prototype.replaceAll = function (search, replacement) { var target = this; return target.replace(new RegExp(search, "g"), replacement); }; const translateStringToFR = async (text) => { const res = await fetch( "https://api-translate.systran.net/translation/text/translate?key=f1065448-0928-4a5f-83eb-f82b1ad64035", { method: "POST", body: JSON.stringify({ input: [text], target: "fr", source: "en", }), headers: { "Content-Type": "application/json" }, } ); return (await res.json()).outputs[0].output; }; const getMonthIndex = (month) => { const indexMonth = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ].findIndex((monthOfYear) => monthOfYear == month); if (indexMonth < 9) { return `0${indexMonth + 1}`; } else if (indexMonth == -1) { return `01`; } return indexMonth + 1; }; const getMonthTextByIndex = (monthIndex) => { return [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre", ][monthIndex]; }; const mappingAttributsEngToFr = (attributName) => { const mappingAttributsEngToFrArr = { "Display size": "Taille d'écran", "Display resolution": "Résolution d'écran", "Camera pixels": "Pixels de la caméra", "Video pixels": "Pixels vidéos", "RAM size": "Taille de la RAM", Chipset: "Chipset", "Battery size": "Taille de la batterie", "Battery type": "Type de batterie", }; return mappingAttributsEngToFrArr[attributName]; }; const orderDevicesByReleaseDate = async (devices) => { let ignoreMonthDateRelease; devices = devices.map((device) => { ignoreMonthDateRelease = false; let dateReleaseDeviceTxt = device.description; if (device.description && device.description.includes(".")) { dateReleaseDeviceTxt = device.description.split(".")[1].trimStart(); } dateReleaseDeviceTxt = dateReleaseDeviceTxt.replace("Announced", ""); let dateReleaseDevice; dateReleaseDevice = new Date( `${dateReleaseDeviceTxt.split(" ")[2]}-${getMonthIndex( dateReleaseDeviceTxt.split(" ")[1] )}-01T12:00:00` ); if ("Invalid Date" == dateReleaseDevice.toString()) { let matchedMonth = dateReleaseDeviceTxt.match( /(January|February|March|April|May|June|July|August|September|October|November|December)/i ); let monthIndex = null; if (matchedMonth && matchedMonth.length) { monthIndex = getMonthIndex(matchedMonth[0].substring(0, 3)); } dateReleaseDeviceTxt = dateReleaseDeviceTxt.match("[0-9]{4}")?.[0]; if ( dateReleaseDeviceTxt && dateReleaseDeviceTxt.length == 4 && !isNaN(dateReleaseDeviceTxt) ) { dateReleaseDevice = new Date( dateReleaseDeviceTxt, monthIndex ? parseInt(monthIndex) : 1 ); ignoreMonthDateRelease = monthIndex ? false : true; } else { dateReleaseDevice = null; } } let id = device.id.includes("-") ? device.id.split("-")[1] : device.id; return { customId: parseInt(id), dateRelease: dateReleaseDevice, ignoreMonthDateRelease, ...device, }; }); devices.sort((deviceA, deviceB) => deviceB.customId - deviceA.customId); return devices; }; const buildWooShortDescription = (device) => { let shortDescription = ""; const quickSpecs = device.quickSpec; Object.keys(quickSpecs).forEach((quickSpec, index) => { if (quickSpecs[quickSpec]) { shortDescription += ` ${mappingAttributsEngToFr(quickSpec)} ${quickSpecs[ quickSpec ] .replace(/\s+/g, " ") .replace("RAM ", "")}`; if (index !== Object.keys(quickSpecs).length - 1) { shortDescription += ", "; } } }); return (shortDescription + ".").replace("\n", ""); }; const buildWooImages = async (img, brand, imgURLs = [], miHomeFlag = false) => { let wooImages = [{ src: img }], i; let ratio, newWidth, newHeight, stepWidth = 0; console.log("img", img); console.log("imgurls", imgURLs); if (!imgURLs || !imgURLs.length) { if (!miHomeFlag) { if (img) { for (i = 1; ; i++) { if ( await urlExist( img .replace("bigpic", "pics/" + brand) .replace(".jpg", `-${i}.jpg`) ) ) { wooImages.push({ src: img .replace("bigpic", "pics/" + brand) .replace(".jpg", `-${i}.jpg`), }); } else { break; } } } if (i !== 1) { delete wooImages.shift(); } } else { wooImages = [{ src: img }]; } } else { wooImages = [ ...imgURLs.map((imgURL) => { return { src: imgURL }; }), ]; /*if (img) { wooImages.unshift({ src: img }); }*/ } for (let i = 0; i < wooImages.length; i++) { const { filename } = await downloadImage.image({ url: wooImages[i].src, dest: dirname(fileURLToPath(import.meta.url)) + "/tmp", }); let baseImage = await Jimp.read( dirname(fileURLToPath(import.meta.url)) + "/base.png" ); let phoneImage = await Jimp.read(filename); stepWidth = 0; do { ratio = phoneImage.getHeight() / phoneImage.getWidth(); newWidth = minWidthImage - stepWidth; newHeight = ratio * newWidth; stepWidth += 10; } while (newHeight > maxHeightImage); await phoneImage.resize(newWidth, newHeight); await baseImage.blit( phoneImage, baseImage.getWidth() / 2 - newWidth / 2, baseImage.getHeight() / 2 - newHeight / 2 ); await baseImage.background(0xffffffff); await baseImage.writeAsync( dirname(fileURLToPath(import.meta.url)) + "/tmp/min/" + filename.replace(/^.*[\\/]/, "") ); let { source_url } = await wp.uploadPhotoBuffer( dirname(fileURLToPath(import.meta.url)) + "/tmp/min/" + filename.replace(/^.*[\\/]/, "") ); wooImages[i].src = source_url; } await fsExtra.emptyDirSync(dirname(fileURLToPath(import.meta.url)) + "/tmp"); await fs.mkdirSync(dirname(fileURLToPath(import.meta.url)) + "/tmp/min"); return wooImages; }; const transformValueAttributsToGSM = async ( valueAttrs, flagTranslate = false ) => { let valueAttrsGSM = []; if (valueAttrs) { for (const valueAttr of valueAttrs) { if (valueAttr) { if (valueAttr === "Yes") valueAttrsGSM.push("Oui"); else if (valueAttr === "No") valueAttrsGSM.push("Non"); else if (flagTranslate == true) valueAttrsGSM.push(await translateStringToFR(valueAttr)); else valueAttrsGSM.push( valueAttr .replaceAll("inches", "pouces") .replaceAll("inches", "pouces") .replaceAll("density", "densité") .replaceAll("Unspecified", "Non spécifié") .replaceAll("wired", "filaire") .replaceAll("inches", "pouces") .replaceAll("body", "corps") .replaceAll("head", "tête") .replaceAll("non-removable", "non amovible") .replaceAll("Up to", "Jusqu'à") ); } } } return valueAttrsGSM; }; const buildRomAttributeOptions = async (romOptions) => { let newOptions = []; let stockageInterneOptions = []; romOptions = typeof romOptions == "string" ? [romOptions] : romOptions; console.log(romOptions); romOptions && romOptions.map((option) => { if (option.includes(",")) { stockageInterneOptions = option .split(",") .map((stockageInterneOption) => /^\d+ Go \d+ Go RAM$/.test(stockageInterneOption) ? stockageInterneOption.trim().replaceAll("GB", " Go").trim() : stockageInterneOption.trim() ); newOptions.push(...stockageInterneOptions); } else { newOptions.push(option.replaceAll("GB", " Go").trim()); } }); console.log(newOptions); return newOptions; }; const buildRamAttributeOptions = async (ramOptions, stockageInterneOptions) => { let newOptions = []; ramOptions.map((option) => { if (option.includes("/")) { const [min, max] = option.replace("GB RAM", "").trim().split("/"); newOptions.push(min.trim() + " Go"); newOptions.push(max.trim() + " Go"); } else if (option.includes("-") && stockageInterneOptions) { if (stockageInterneOptions && stockageInterneOptions.length) { let ramValues = new Set(); stockageInterneOptions.forEach((item) => { const parts = item.split(","); parts.forEach((part) => { const ram = part.match(/\b(\d+)GB (\d+GB) RAM\b/); if (ram) { const ram1 = ram[2].replace("GB", "").trim() + " Go"; ramValues.add(ram1); } }); }); ramValues = Array.from(ramValues); ramValues.length ? newOptions.push(...ramValues) : newOptions.push(option); newOptions = Array.from(new Set(newOptions)); } } else { option ? newOptions.push( option.replace("GB", "").replace("RAM", "").trim() + " Go" ) : null; } }); return newOptions; }; const buildWooAttributs = async (device) => { const wooAttributs = [ { id: 1, name: "Marque", position: 0, visible: true, variation: false, options: [device.brand?.split("-")[0]], }, { id: 24, name: "Date de sortie", position: 0, visible: true, variation: false, options: [ device.dateRelease ? `${ device.ignoreMonthDateRelease ? "" : getMonthTextByIndex(device.dateRelease.getMonth() - 1) } ${device.dateRelease.getFullYear()}` : undefined, ], }, { id: 25, name: "Poids", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Body?.Weight )), ], }, { id: 47, name: "Matériaux", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Body?.Build, true )), ], }, { id: 43, name: "Technologie de réseau", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Network?.Technology )), ], }, { id: 31, name: "Dimensions", position: 10, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Body?.Dimensions )), ], }, { id: 26, name: "SIM", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Body?.SIM, true )), ], }, { id: 16, name: "Type d'écran", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Display?.Type )), ], }, { id: 7, name: "Résolution d'écran", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Display?.Resolution )), ], }, { id: 44, name: "Taille d'écran", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Display?.Size )), ], }, { id: 45, name: "Protection d'écran", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Display?.Protection, true )), ], }, { id: 27, name: "Système d'exploitation", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Platform?.OS )), ], }, { id: 42, name: "Chipset", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Platform?.Chipset )), ], }, { id: 21, name: "Processeur", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Platform?.CPU )), ], }, { id: 41, name: "Puce graphique", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Platform?.GPU )), ], }, { id: 3, name: "Ram", position: 0, visible: true, variation: false, options: [ ...(await buildRamAttributeOptions( device.quickSpec?.["RAM size"].split(","), await transformValueAttributsToGSM( device.detailSpec?.Memory?.Internal ) )), ], }, { id: 46, name: "Slot micro SD", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Memory?.["Card slot"] )), ], }, { id: 28, name: "Stockage interne", position: 0, visible: true, variation: false, options: [ ...(await buildRomAttributeOptions( ...(await transformValueAttributsToGSM( device.detailSpec?.Memory?.Internal )) )), ], }, { id: 20, name: "Caméra principale", position: 0, visible: true, variation: false, options: [ device.quickSpec?.["Camera pixels"] + " " + ( await transformValueAttributsToGSM( device.detailSpec?.["Main Camera"]?.Features ) ).join(","), ], }, { id: 48, name: "Caméra principale (Vidéo)", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.["Main Camera"]?.Video )), ], }, { id: 50, name: "Caméra principale (Triple)", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.["Main camera"]?.Triple )), ], }, { id: 19, name: "Caméra selfie", position: 0, visible: true, variation: false, options: [ ( await transformValueAttributsToGSM( device.detailSpec?.["Selfie camera"]?.Single ) ).join(",") + ", " + ( await transformValueAttributsToGSM( device.detailSpec?.["Selfie camera"]?.Features ) ).join(","), ], }, { id: 49, name: "Caméra selfie (Vidéo)", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.["Selfie camera"]?.Video, true )), ], }, { id: 32, name: "WLAN", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM(device.detailSpec?.Comms?.WLAN)), ], }, { id: 33, name: "Bluetooth", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Comms?.Bluetooth )), ], }, { id: 38, name: "NFC", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM(device.detailSpec?.Comms?.NFC)), ], }, { id: 40, name: "Port infrarouge", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Comms?.["Infrared port"] )), ], }, { id: 39, name: "Positionnement", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Comms?.Positioning )), ], }, { id: 37, name: "Radio", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Comms?.Radio )), ], }, { id: 29, name: "USB", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM(device.detailSpec?.Comms?.USB)), ], }, { id: 51, name: "Haut-parleur", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Sound?.["Loudspeaker "], true )), ], }, { id: 52, name: "Prise jack 3,5 mm", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Sound?.["3.5mm jack "], true )), ], }, { id: 30, name: "Caractéristiques", position: 0, visible: true, variation: false, options: [ ...( await transformValueAttributsToGSM( device.detailSpec?.Features?.Sensors, true ) ).reduce( (acc, curr) => acc.concat(curr.split(",").map((item) => item.trim())), [] ), ], }, { id: 6, name: "Batterie mAh", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Battery?.Type )), ], }, { id: 34, name: "Mise en charge", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Battery?.Charging )), ], }, { id: 2, name: "Couleurs", position: 0, visible: true, variation: false, options: [ ...( await transformValueAttributsToGSM( device.detailSpec?.Misc?.Colors, true ) ).reduce( (acc, curr) => acc.concat(curr.split(",").map((item) => item.trim())), [] ), ], }, { id: 36, name: "Modèles", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM( device.detailSpec?.Misc?.Models )), ], }, { id: 53, name: "Taux d'Absorption Spécifique", position: 0, visible: true, variation: false, options: [ ...(await transformValueAttributsToGSM(device.detailSpec?.Misc?.SAR)), ], }, ] .filter( (attribut) => !attribut.options.every( (option) => option === undefined || option === "," || option === "undefined" || option.trim() === "" ) ) .map((attribut) => { return { ...attribut, options: attribut.options.map((option) => option .replace(/\n/g, ",") .replace(/\s+/g, " ") .replace(/,$/, "") .trim() .replace(/undefined/g, "") ), }; }); return wooAttributs.map((element, index) => ({ ...element, position: index, })); }; const getProductByTitleGSM = async (title) => { try { const response = await WooCommerce.get("products", { search: '"' + title + '"', // Exact match using quotes per_page: 50, // Vous pouvez ajuster cela selon vos besoins }); if (response.data.length == 0) return null; return response.data.filter((product) => product.name == title).length ? response.data.filter((product) => product.name == title)[0] : null; } catch (error) { // Gérez les erreurs console.error("Erreur lors de la récupération du produit:", error.message); throw error; } }; const updateDeviceSpecGSM = async (productId, attributes) => { try { const response = await WooCommerce.put(`products/${productId}`, { attributes, }); return response.data; } catch (error) { console.error("Error updating product attributes:", error.response.data); throw error; } }; const addDeviceToGSMMAPoC = async (device, miHomeFlag = false) => { /*const deviceGSM = await getProductByTitleGSM(device.name); console.log('product exist ?', deviceGSM && deviceGSM.id); console.log('processing ... ============>', device.name);*/ const categories = device.name.toLowerCase().includes("watch") ? [ { id: 699, }, { id: 229, }, ] : device.name.toLowerCase().includes("tab") || device.name.toLowerCase().includes("pad") ? [ { id: 226, }, ] : [ { id: 225, }, ]; let date_created = device.dateRelease; if (date_created) { date_created = /*new Date().toISOString();*/ date_created.toISOString(); } else { date_created = new Date().toISOString(); } const data = { name: device.name, status: "publish", date_created, date_modified: date_created, catalog_visibility: "visible", meta_data: [ { key: "_specifications_display_attributes", value: "yes", }, ], reviews_allowed: false, type: "simple", stock_status: "onbackorder", short_description: miHomeFlag ? device.description : buildWooShortDescription(device), categories, attributes: miHomeFlag ? device.attributes : await buildWooAttributs(device), images: await buildWooImages( device.img, device.brand?.split("-")[0], device.imgURLs, miHomeFlag ), }; try { console.log("Start saving ", device.name); /*if (deviceGSM) { console.log('put'); await WooCommerce.put(`products/${deviceGSM.id}`, data); } else { console.log('post'); }*/ await WooCommerce.post("products", data); } catch (error) { console.log(error); } console.log("Done "); console.log("start sleep ..."); await new Promise((resolve) => setTimeout(resolve, 10)); }; const loadSavedDevices = async (suffix) => { return JSON.parse( await fs.readFileSync( dirname(fileURLToPath(import.meta.url)) + `/saved-devices${suffix ? "-" + suffix : ""}.json` ) ); }; const refreshSavedDevices = async (savedDevices, suffix) => { await fs.writeFileSync( dirname(fileURLToPath(import.meta.url)) + `/saved-devices${suffix ? "-" + suffix : ""}.json`, JSON.stringify(savedDevices) ); }; const updateAttributsProductsWoo = async () => { savedDevices = await loadSavedDevices("attr"); let devices = []; for await (const brand of brands) { devices.push( ...(await gsmarena.catalog.getBrand(brand)).map((device) => { return { brand: brand.split("-")[0], ...device }; }) ); } console.log(devices.length); devices = devices.filter((device) => !savedDevices.includes(device.id)); console.log( "List device to save", devices.map((device) => device.id) ); let attrUpdated = null; let startIndex = 1137; for (let i = startIndex; i < devices.length; i++) { const device = devices[i]; const deviceGSM = await getProductByTitleGSM(device.name); console.log(i + 1 + "/" + devices.length); if (deviceGSM) { let detailDevice = await gsmarena.catalog.getDevice(device.id); if (!device.dateRelease) { detailDevice = { ...detailDevice, ...( await orderDevicesByReleaseDate([ { ...detailDevice, id: device.id }, ]) )[0], }; } detailDevice = { ...device, ...detailDevice, price: detailDevice.pricesList ? detailDevice.pricesList : undefined, detailSpec: detailDevice.detailSpec.reduce( (obj, item) => ( (obj[item.category] = item.specifications.reduce( (obj, item) => ((obj[item.name] = item.values), obj), {} )), obj ), {} ), quickSpec: detailDevice.quickSpec.reduce( (obj, item) => ((obj[item.name] = item.value), obj), {} ), }; console.log("UPDATE START ==>", detailDevice.name); attrUpdated = await buildWooAttributs(detailDevice); console.log("UPDATE WOO ID : ==>", deviceGSM.id); await updateDeviceSpecGSM(deviceGSM.id, attrUpdated); console.log("UPDATE DONE ==>", detailDevice.name); savedDevices.push(device.id); await refreshSavedDevices(savedDevices, "attr"); } } }; const main = async () => { try { savedDevices = await loadSavedDevices(); let devices = []; for await (const brand of brands) { await devices.push( ...( await gsmarena.catalog.getBrand(brand, false) ).map(async (device) => { return { brand: brand.split("-")[0], ...device }; }) ); } devices = await Promise.all(devices.map((promise) => promise)); devices = await orderDevicesByReleaseDate(devices); devices = devices.filter( (device) => !savedDevices.includes(device.id) && device.dateRelease >= fromReleaseDate ); devices = [ ...devicesSyncAlone .filter((device) => !savedDevices.includes(device)) .map((device) => { return { id: device, brand: device.split("_")[0], }; }), ...devices, ]; console.log( "List device to save", devices.map((device) => device.id) ); for await (const [i, device] of devices.entries()) { try { console.log(i + 1 + "/" + devices.length); let detailDevice = await gsmarena.catalog.getDevice(device.id); if (!device.dateRelease) { detailDevice = { ...detailDevice, ...( await orderDevicesByReleaseDate([ { ...detailDevice, id: device.id }, ]) )[0], }; } detailDevice = { ...device, ...detailDevice, price: detailDevice.pricesList ? detailDevice.pricesList : undefined, detailSpec: detailDevice.detailSpec.reduce( (obj, item) => ( (obj[item.category] = item.specifications.reduce( (obj, item) => ((obj[item.name] = item.values), obj), {} )), obj ), {} ), quickSpec: detailDevice.quickSpec.reduce( (obj, item) => ((obj[item.name] = item.value), obj), {} ), }; await addDeviceToGSMMAPoC(detailDevice); savedDevices.push(device.id); await refreshSavedDevices(savedDevices); } catch (err) { console.log(err); } } if (devices.length) { await mainSitemap(); } } catch (err) { console.log(err); } }; main();