-
Notifications
You must be signed in to change notification settings - Fork 4
/
03_generateData.js
88 lines (77 loc) · 2.71 KB
/
03_generateData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var fs = require('fs');
const util = require('util');
// Must sync up with 02_getOSJSONs.js
const BATCHSIZE = 30;
const TOTALSUPPLY = 11305;
const OSINPUTDATADIR = "osraw/";
let osrecords = {};
for (let i = 0; i < TOTALSUPPLY; i += BATCHSIZE) {
var filename = OSINPUTDATADIR + i + ".json";
// console.log(filename);
try {
var data = JSON.parse(fs.readFileSync(filename, "utf8"));
if (data.assets == null || data.assets.length == 0) {
console.log("Assets missing for: " + i);
}
for (let j = 0; j < data.assets.length; j++) {
const asset = data.assets[j];
osrecords[asset.token_id] = asset;
}
} catch (e) {
console.log("Error in file: " + filename);
}
}
// console.log(osrecords[0]);
const INPUTDATADIR = "raw/";
let records = [];
var filename = INPUTDATADIR + "all.json";
try {
var data = JSON.parse(fs.readFileSync(filename, "utf8"));
if (data.length != TOTALSUPPLY) {
console.log("Error. Expecting data.length: " + data.length + " to be " + TOTALSUPPLY);
}
console.log(data.length);
for (const record of data) {
const osData = osrecords[record.tokenId];
if (!osData) {
console.log("Cannot find OS data for: " + data.tokenId);
}
record.imageMosaic = null;
for (let k in record.attributes) {
const attribute = record.attributes[k];
if (attribute.trait_type == 'HYPE TYPE') {
if (attribute.value == 'HYPED AF (ANIMATED)') {
record.imageMosaic = record.tokenId + '.png';
break;
}
}
}
record.permalink = osData.permalink;
const localCopy = "./arweaveimages/" + record.tokenId + "_" + record.imageArweave.replace("https://arweave.net/", "") + (record.imageMosaic == null ? ".png" : ".gif");
record.images = [localCopy, record.image, record.imageArweave, osData.image_url, osData.image_preview_url, osData.image_thumbnail_url];
delete record.image;
delete record.imageArweave;
if (record.tokenId == 0 || record.tokenId == 1) {
console.log(record);
}
records.push(record);
}
} catch (e) {
console.log("Error in file: " + filename);
}
console.log(JSON.stringify(records[666], null, 2))
const OUTPUTMINREPORT = "bastardData.min.js";
(async () => {
await fs.writeFile(OUTPUTMINREPORT, "const BASTARDDATA=" + JSON.stringify(records) + ";", (err) => {
if (err) throw err;
console.log('Data written to file: ' + OUTPUTMINREPORT);
});
})();
const OUTPUTREPORT = "bastardData.js";
(async () => {
await fs.writeFile(OUTPUTREPORT, "const BASTARDDATA=" + JSON.stringify(records, null, 2) + ";\n\nmodule.exports = {\n BASTARDDATA\n}", (err) => {
if (err) throw err;
console.log('Data written to file: ' + OUTPUTREPORT);
});
})();
console.log(process.cwd());