Advertisement
call23re

Get Owner Data

Aug 19th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. const fetch = require('node-fetch'); // comment this line out if you're running in the browser
  4. const fs = require('fs'); // comment this line out if you're running in the browser
  5. const base = `https://inventory.roblox.com/v1/assets`;
  6.  
  7. const SAVE_TO_FILE = true;
  8. const SAVE_JSON = true;
  9.  
  10. let options = {
  11.     AssetID: 100425940,
  12.     SortOrder: 'Asc',
  13.     Limit: 100,
  14.     Cursor: '',
  15.     FindSerials: [1, 6, 23, 25],
  16.     CountDeleted: true
  17. };
  18.  
  19. function Get(assetid, cursor = '', sortOrder = 'Asc', limit = 10) {
  20.     if (!assetid) {
  21.         throw new Error('Include asset id');
  22.     }
  23.     if (sortOrder != 'Asc' && sortOrder != 'Desc' && sortOrder != '') {
  24.         sortOrder = 'Asc';
  25.     };
  26.     if (limit != 10 && limit != 25 && limit != 50 && limit != 100 && limit != '') {
  27.         limit = 10;
  28.     };
  29.     return new Promise((resolve, reject) => {
  30.         let url = `${base}/${assetid}/owners/?sortOrder=${sortOrder}&limit=${limit}&cursor=${cursor}`;
  31.         fetch(url)
  32.             .then(res => res.json())
  33.             .then(data => {
  34.                 resolve(data);
  35.             })
  36.             .catch(err => console.warn(err));
  37.     });
  38. };
  39.  
  40. let [SerialOwners, Owners, Total, TotalBC, TotalBanned] = [{}, [], 0, 0, 0];
  41.  
  42. async function Run() {
  43.     let data = await Get(options.AssetID, options.Cursor, options.SortOrder, options.Limit);
  44.     for (let item of data.data) {
  45.         let ownerData;
  46.         if (item.owner) {
  47.             Total += 1;
  48.             ownerData = {
  49.                 Username: item.owner.username,
  50.                 ID: item.owner.userId,
  51.                 userAssetId: item.userAssetId,
  52.                 PurchaseTime: item.created,
  53.                 BC: item.owner.buildersClubMembershipType
  54.             };
  55.             if (item.owner.buildersClubMembershipType != 0) {
  56.                 TotalBC += 1;
  57.             };
  58.         } else {
  59.             if (options.CountDeleted) {
  60.                 Total += 1;
  61.             };
  62.             TotalBanned += 1;
  63.             ownerData = {
  64.                 Username: '[DELETED]',
  65.                 ID: '[DELETED]',
  66.                 userAssetId: item.userAssetId,
  67.                 PurchsaeTime: item.created
  68.             };
  69.         };
  70.         if (item.serialNumber) {
  71.             if (options.FindSerials.includes(item.serialNumber)) {
  72.                 SerialOwners[item.serialNumber] = ownerData;
  73.             };
  74.         };
  75.         if (SAVE_JSON) {
  76.             Owners.push(ownerData);
  77.         };
  78.         if (SAVE_TO_FILE) {
  79.             // comment out the below section if you are running in the browser
  80.             if (item.owner) {
  81.                 fs.appendFileSync(`${options.AssetID}.txt`, `${item.owner.userId} - ${item.owner.username}\r\n`);
  82.             } else if (options.CountDeleted) {
  83.                 fs.appendFileSync(`${options.AssetID}.txt`, `[DELETED] - [DELETED]\r\n`);
  84.             };
  85.         };
  86.     };
  87.     if (data.nextPageCursor != null && data.nextPageCursor != '') {
  88.         options.Cursor = data.nextPageCursor;
  89.         Run();
  90.     } else {
  91.         console.log(`Total Owners (including Roblox): ${Total}\nTotal BC Owners (including Roblox): ${TotalBC}\nTotal Deleted Owners: ${TotalBanned}\nTotal Without Deleted Owners (including Roblox): ${Total - TotalBanned}\nFound Serials:\n`, SerialOwners);
  92.         // comment out the below section if you are running in the browser
  93.         fs.appendFileSync(`${options.AssetID}.txt`, `Total Owners (including Roblox): ${Total}\nTotal BC Owners (including Roblox): ${TotalBC}\nTotal Deleted Owners: ${TotalBanned}\nTotal Without Deleted Owners (including Roblox): ${Total - TotalBanned}`);
  94.         if (SAVE_JSON) {
  95.             fs.writeFileSync(`${options.AssetID}.json`, JSON.stringify(Owners));
  96.         };
  97.     };
  98. };
  99.  
  100. Run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement