-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddTotal.js
50 lines (45 loc) · 1.32 KB
/
addTotal.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
const fs = require('fs')
let count = 0
let paidContracts = []
// course contracts
const courseContractArr = fs.readFileSync('coursedata.json', 'utf-8')
.split(/\r?\n/)
courseContractArr.pop()
// course & price
const priceStr = fs.readFileSync('hqindex.json', 'utf-8')
console.log(JSON.parse(priceStr).published.length)
const priceArr = JSON.parse(priceStr).published
courseContractArr.forEach(
contract => {
let contractObj = JSON.parse(contract)
let {courseId, total} = contractObj
total = 0
// if (Object.prototype.toString.call(courseId) === '[object String]' ) {
// console.log(contractObj);
// }
// console.log(Object.prototype.toString.call(courseId));
courseId.forEach(
// Array.prototype.forEach.call(courseId,
course => {
for (let {price, link} of priceArr) {
if (link.slice(1) === course) {
total += parseInt(price)
}
}
}
)
++count
contractObj.total = total
paidContracts.push(contractObj)
}
)
console.log(count) // 272
console.log(paidContracts.length)
let finalStr = paidContracts.map(
item => JSON.stringify(item)
).join('\n')
fs.writeFile('paidCoursesContract.json', finalStr, (err) => {
if (err) throw err
console.log('The file has been restructured!')
})
// if (contractObj._id.$oid === i._id.$oid) {