suhaotian / ucrx

unzip .crx from terminal...

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-xlsx

suhaotian opened this issue · comments

commented

const xlsx = require('node-xlsx')
const fs = require('fs')
const fetch = require('node-fetch')
const sleep = require('./sleep')
const download = require('./download')

const api = 'url'
const nameIndex = 1
const appIdIndex = 2

// const result = xlsx.parse(${__dirname}/app.xlsx, {cellDates: true})
// result[0].data[0].push('包名')

// fs.writeFileSync('./output.xlsx', xlsx.build(result))

const result = xlsx.parse(${__dirname}/app.xlsx, {cellDates: true})

const data = result[0].data

// console.log(result)

// fetch(${api}${data[1][nameIndex]}).then(function(res){
// return res.json()
// }).then(data=> {
// console.log(data)
// })
// iconUrl
// pkgName
// return
// /*
const titles = data.shift()
let j = 0

const notfounds = []

const finalResult = []

finalResult.push([ '筛选日期',
'应用名称',
'应用ID',
'广告主名',
'广告主ID',
'最后出价',
'平均出价',
'每日应用消耗',
'调价次数',
'预算消耗率',
'日限额',
'二级分类',
'三级分类',
'当前状态',
'是否通过弱推审核',
'应用包名'
])

data.reduce(function(chain, item) {
return chain.then(function() {
return fetch(${api}${encodeURIComponent(item[nameIndex])}).then(function(res){
return res.json()
}).then(function(resData) {
j++
var is_found = false
for(let i = 0;i<resData.appList.length;i++) {
const itemData = resData.appList[i]
//itemData.appName == item[nameIndex] &&
if (itemData.appId == item[appIdIndex]) {
// 下载图标
if (itemData.iconUrl) {
download(itemData.iconUrl, ./icons/${item[nameIndex]}-${item[appIdIndex]}.png, function(){})
} else {
console.log(${item[nameIndex]}-${item[appIdIndex]}未找到图标)
}
is_found = true
console.log(Got! ${item[nameIndex]} - ${j})
item.push(itemData.pkgName)
finalResult.push(item)
break
}
}
if (!is_found) {
console.log('not found')
notfounds.push(${item[nameIndex]} - ${j})
finalResult.push(item)
}
return true
}).then(sleep(100)).catch(function(err) {
item.push('')
finalResult.push(item)
notfounds.push(${item[nameIndex]} - ${j})
console.log(error: ${item[nameIndex]} - ${item[appIdIndex]})
})
})
}, Promise.resolve()).then(function() {
console.log('done!')
console.log('not founds:')
console.log(notfounds)
// console.log(finalResult.forEach)
// result[0].data = finalResult

fs.writeFileSync('./'+(new Date().getTime())+'.xlsx', xlsx.build([{name: 'Sheet1', data: finalResult}]))
}).catch(function(e) {
console.log(e)
})
// */