0
0
mirror of https://github.com/Maks1mS/free-ozon-dpr.git synced 2024-12-25 03:14:37 +03:00
free-ozon-dpr/scripts/update/sevenDostavka.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-06-06 20:31:02 +03:00
import fs from "node:fs/promises";
import { JSDOM } from "jsdom";
2024-06-08 19:23:22 +03:00
const OUTPUT_FILE = "data/99_sevenDostavka.json";
2024-06-06 20:31:02 +03:00
const linkRegexp = new RegExp(/https:\/\/ozon\.ru\/point\/\d+/);
async function sevenDostavka() {
const res = await fetch("https://dostavka.7telecom.ru");
const htmlText = await res.text();
const dom = new JSDOM(htmlText);
const document = dom.window.document;
const scripts = document.querySelectorAll("script");
for (let script of scripts) {
if (script.textContent.includes("ДОБАВИТЬ ПУНКТ ВЫДАЧИ В ПРИЛОЖЕНИЕ")) {
let x = script.textContent.split("[\n{\n").pop().split("\n},\n]")[0];
if (x) {
const points = new Function(`return [{${x}}]`)();
fs.writeFile(
2024-06-08 19:23:22 +03:00
OUTPUT_FILE,
2024-06-06 20:31:02 +03:00
JSON.stringify(
{
name: "7dostavka",
source: "https://dostavka.7telecom.ru",
points: points.map((point) => ({
coordinates: [
parseFloat(point["lng"]),
parseFloat(point["lat"]),
],
link: linkRegexp.exec(point.descr)[0],
name: point.title,
address: point.title,
operationTime: "неизвестно",
})),
},
undefined,
4
)
);
}
}
}
}
2024-06-08 19:23:22 +03:00
export default sevenDostavka;