Repository navigation
Expand file tree
/
Copy pathcreate-metadata.js
More file actions
46 lines (45 loc) · 1.51 KB
/
Copy pathcreate-metadata.js
File metadata and controls
46 lines (45 loc) · 1.51 KB
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
const Farmernet = artifacts.require('FarmernetLand')
const fs = require('fs')
const metadataTemple = {
"name": "",
"description": "",
"image": "",
"attributes": [
{
"trait_type": "Longitude",
"value": 0
},
{
"trait_type": "Latitude",
"value": 0
},
{
"trait_type": "Carbon_emissions",
"value": 0
}
]
}
module.exports = async callback => {
const dnd = await Farmernet.deployed()
length = await dnd.getNumberOfLands()
index = 0
while (index < length) {
console.log('Let\'s get the overview of your Land ' + index + ' of ' + length)
let LandMetadata = metadataTemple
let LandOverview = await dnd.Lands(index)
index++
LandMetadata['name'] = LandOverview['name']
if (fs.existsSync('metadata/' + LandMetadata['name'].toLowerCase().replace(/\s/g, '-') + '.json')) {
console.log('test')
continue
}
console.log(LandMetadata['name'])
LandMetadata['attributes'][0]['value'] = LandOverview['longitude']['words'][0]
LandMetadata['attributes'][1]['value'] = LandOverview['latitude']['words'][0]
LandMetadata['attributes'][2]['value'] = LandOverview['carbon_emission']['words'][0]
filename = 'metadata/' + LandMetadata['name'].toLowerCase().replace(/\s/g, '-')
let data = JSON.stringify(LandMetadata)
fs.writeFileSync(filename + '.json', data)
}
callback(dnd)
}