Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
2.8 kB
5
Indexable
Never
// записи которые можно удалить

import axios from "axios";
import fs from "fs";
import HTMLParser from 'node-html-parser'

let current = 0
const max = 10000
const startId = 635382510
const streams = 15

//62
function encodeNumber(number) {
    const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    const base = alphabet.length;
    let result = "";

    while (number > 0) {
        let remainder = number % base;
        result = alphabet[remainder] + result;
        number = Math.floor(number / base);
    }
    return result;
}

let q = []


let json = JSON.parse(fs.readFileSync('delete.json', "utf-8")) || [];
const start = json[json.length - 1]?.i || startId
console.log(json.length);
(async () => {
    async function getDel(i) {
        const id = q[i]
        if (current >= max) {
            return
        }
        try {
            const code = encodeNumber(id)
            const resp = await axios(`https://yclients.com/c/${code}`)
            const document = HTMLParser.parse(resp.data)
            const el = document.querySelector('erp-notifications-record-confirmation')

            const canDelete = el.getAttribute(':has-delete-record')
            const salonTitle = JSON.parse(el.getAttribute(':salon-title'))
            const address = JSON.parse(el.getAttribute(':address'))
            const services = JSON.parse(el.getAttribute(':services'))
            const date = JSON.parse(el.getAttribute(':date'))


            //запись нельзя удалить идем к следующей
            if (canDelete !== 'true') {
                q[i] = Math.max(...q) + 1
                return getDel(i)
            }

            console.log(current, salonTitle);
            //записи которые можно удалить добавляем в базу
            json.push({
                salonTitle,
                address,
                code,
                services,
                date,
                i: id
            })

            //TODO
            //!!!!!!!!!!!!!! УДАЛЕНИЕ НЕ ТРЕБУЕТ ДОПОЛНИТЕЛЬНЫХ АВТОРИЗАЦИЙ !!!!!!!!!!!!!!
            //!!!//await axios.delete(`https://yclients.com/c/${code}/delete`)//!!!//
            //!!!!!!!!!!!!!! ДЕСТРУКТИВНОЕ ДЕЙСТВИЕ НЕ ИСПОЛЬЗОВАТЬ !!!!!!!!!!!!!!

            q[i] = Math.max(...q) + 1
            current++
            return getDel(i)
        } catch (e) {
            q[i] = Math.max(...q) + 1
            return getDel(i)
        }
    }


    //streams потоков
    for (let i = 0; i < streams; i++) {
        q.push(i + start)
        getDel(i).then()
    }

    setInterval(() => {
        fs.writeFileSync('delete.json', JSON.stringify(json, null, 2))
    }, 5000)
})();