Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
2.4 kB
2
Indexable
Never
import * as fs from 'fs'
import {
  createRequire
} from 'module' // Bring in the ability to create the 'require' method
import * as cheerio from 'cheerio'
const require = createRequire(import.meta.url)
const { PendingXHR } = require('pending-xhr-puppeteer')
const request = require('request')

go()
async function go () {
  const rawdata = fs.readFileSync('allnftlist.json')
  const datajson = JSON.parse(rawdata)
  for await (const nameofnft of datajson) {
    await loop(nameofnft.collectionTicker)
    console.log('finish')
  }
}

async function loop (namenft) {
  console.log(namenft)
  const test = []
  const Increment = 20
  for (let i = 0; i <= (5000); i += Increment) {
    let urlsale
    if (i < 1) {
      urlsale = 'https://gateway.deadrare.io/?operationName=ListCachedNfts&variables={"filters":{"collection":"' + namenft + '","isBurned":false},"sort":"NUMBER","pagination":{"limit":40}}&extensions={"persistedQuery":{"version":1,"sha256Hash":"988586ecc7b8f8d34ca3d3c573332d4dc35d12c20dfd0110d730fb27e5e8cf6a"}}'
    }
    if (i > 1) {
      urlsale = 'https://gateway.deadrare.io/?operationName=ListCachedNfts&variables={"filters":{"collection":"' + namenft + '","isBurned":false},"sort":"NUMBER","pagination":{"limit":40,"offset":' + i + '}}&extensions={"persistedQuery":{"version":1,"sha256Hash":"988586ecc7b8f8d34ca3d3c573332d4dc35d12c20dfd0110d730fb27e5e8cf6a"}}'
    }

    await request({
      method: 'get',
      headers: { 'X-Requested-With': 'XMLHttpRequest' },
      url: urlsale
    }, (err, res, body) => {
      if (err) {
        return console.error(err)
      }
      const $ = cheerio.load(body)
      const element = $('body').text()

      const obj = JSON.parse(element)

      const allvalue = obj.data.listCachedNfts.results

      for (const key in allvalue) {
        if ((allvalue[key].attributes)) {
          allvalue[key].attributes = JSON.parse(allvalue[key].attributes)
          allvalue[key].id = allvalue[key].id.split('-').splice(-1)
        }
      }
      const result = allvalue.reduce((r, a) => r.concat(a), [])
      test.push(result)

      const resulttotal = result2.sort((a, b) => b.nonce - a.nonce)

      fs.writeFileSync('./globalinfo/' + namenft + '.json', JSON.stringify(resulttotal, null, '\t')).then(() => console.log('Enregistré'))
      test.pop()
    })
  }
}