forked from chaos511/HoneyGainGrapher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenidmap.js
69 lines (64 loc) · 2.04 KB
/
genidmap.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
const fs = require('fs');
function wsReadFile(fpath){
return new Promise(resolve => {
fs.readFile(fpath, function(error, content) {
if (error) {
console.log("Error 404: File "+fpath+" Not Found");
resolve("{}")
}
else {
resolve(content)
}
});
})
}
async function main(){
var content=await wsReadFile("data.json")
jsonData=JSON.parse('['+content.slice(0,-2)+']')
var dataBuffer=""
var idmap
try{
idmap=JSON.parse(await wsReadFile("idmap.json","{}"))
}catch{
}
if(idmap==undefined){
idmap={}
}
for(device in jsonData){
if(idmap[jsonData[device]['1']]==undefined||idmap[jsonData[device]['1']].title!=(jsonData[device]['4'])){
idmapData={
id:jsonData[device]['1'],
manufacturer:(jsonData[device]['2']),
model:(jsonData[device]['3']),
title:(jsonData[device]['4']),
platform:(jsonData[device]['5']),
version:(jsonData[device]['6']),
}
console.log("device not found or changed adding: "+JSON.stringify(idmapData))
idmap[jsonData[device]['1']]=idmapData
}
deviceData={
1:jsonData[device]['1'],
// 2:encodeURI(jsonData[device].['2']),
// 3:encodeURI(jsonData[device].['3']),
// 4:encodeURI(jsonData[device].['4']),
// 5:encodeURI(jsonData[device].['5']),
// 6:encodeURI(jsonData[device].['6']),
7:jsonData[device]['7'],
8:jsonData[device]['8'],
9:jsonData[device]['9'],
};
dataBuffer+=JSON.stringify(deviceData)+",\n"
}
fs.writeFile("data.json", dataBuffer, function(err) {
if(err) {
return console.log(err);
}
});
fs.writeFile("idmap.json", JSON.stringify(idmap), function(err) {
if(err) {
return console.log(err);
}
});
}
main()