Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.6 kB
1
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 request = require('request')

go()
async function go () {
  const test = []
  const Increment = 40
  const rawdata = fs.readFileSync('allnftlist.json')
  const datajson = JSON.parse(rawdata)

  for (const nameofnft of datajson) {
    console.log(nameofnft.collectionTicker)
    for (let i = 0; i <= (9999 * 1); i += Increment) {
      let urlsale
      if (i < 1) {
        urlsale = 'https://gateway.deadrare.io/?operationName=ListCachedNfts&variables={"filters":{"collection":"' + nameofnft.collectionTicker + '","isBurned":false},"sort":"NUMBER","pagination":{"limit":20}}&extensions={"persistedQuery":{"version":1,"sha256Hash":"988586ecc7b8f8d34ca3d3c573332d4dc35d12c20dfd0110d730fb27e5e8cf6a"}}'
      }
      if (i > 1) {
        urlsale = 'https://gateway.deadrare.io/?operationName=ListCachedNfts&variables={"filters":{"collection":"' + nameofnft.collectionTicker + '","isBurned":false},"sort":"NUMBER","pagination":{"limit":20,"offset":' + i + '}}&extensions={"persistedQuery":{"version":1,"sha256Hash":"988586ecc7b8f8d34ca3d3c573332d4dc35d12c20dfd0110d730fb27e5e8cf6a"}}'
      }
      try {
        request({
          method: 'get',
          headers: { 'X-Requested-With': 'XMLHttpRequest' },
          url: urlsale
        }, (err, res, body) => {
          if (err) {
            return console.error(err)
          } else {
            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 result2 = test.reduce((r, a) => r.concat(a), [])

            const resulttotal = result2.sort((a, b) => b.nonce - a.nonce)
            fs.writeFileSync('./globalinfo/' + nameofnft.collectionTicker + '.json', JSON.stringify(resulttotal, null, '\t'))
          }
        })
      } catch (err) {
        console.log('Une erreur est survenue, on relance')
        console.log(err)
      }
      test.pop()
    }
  }
}