-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
128 lines (109 loc) · 2.47 KB
/
index.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import fs from 'fs'
import path from 'path'
import nodejieba from "nodejieba"
import initData from './src/initData.js'
import _ from './config/config.js'
const sqlite3 = new require('sqlite3').verbose()
const db = new sqlite3.Database(_.DB_PATH)
var result = {}
function subMsg(msg, time, type, des) {
let msgList
let nickName
let message
if (des === 0) {
nickName = _.MY_NICKNAME
message = switchType(msg, type)
} else {
let msgArray = msg.split(':\n')
nickName = msgArray[0]
message = switchType(msgArray[1], type)
}
// console.log(nickName + ': ' + message)
let tempList = result[nickName]
if (tempList) {
tempList.push({
time: time,
msg: message
})
} else {
result[nickName] = [{
time: time,
msg: message
}]
}
}
function switchType(msg, type) {
if (type === _.TYPES.voiceMsg) {
return '[voiceMsg]'
}
if (type === _.TYPES.emoji) {
return '[emoji]'
}
if (type === _.TYPES.voipinviteMsg) {
return '[voipinviteMsg]'
}
if (type === _.TYPES.picture) {
return '[picture]'
}
if (type === _.TYPES.idCard) {
return '[idCard]'
}
return msg
}
db.serialize(function() {
db.each('SELECT CreateTime, Message, Type, Des FROM ' + _.TABLE_NAME, function(err, row) {
if (row.Type === _.TYPES.systemMsg
|| row.Type == _.TYPES.location
|| row.Type == _.TYPES.url
|| row.Type == _.TYPES.videoMsg) {
return false
}
subMsg(row.Message, row.CreateTime, row.Type, row.Des)
})
})
db.close(() => {
initData.init()
initData.genMsgNumData(result)
initData.genTimeData(result)
initData.genAtCountData(result)
// nodejieba.load({
// userDict: './dict/user.dict.utf8',
// });
//
// for (let key in result) {
// let obj = {}
//
// result[key].map(e => {
// let cut = nodejieba.cut(e.msg)
//
// cut.map(el => {
// let count = obj[el]
// if (count) {
// count++
// obj[el] = count
// } else {
// obj[el] = 1
// }
// })
// })
//
// let list = []
// for (let key2 in obj) {
// list.push({
// text: key2,
// size: obj[key2]
// })
// }
//
// list.sort(function(a,b) {
// return b.size - a.size
// })
// list = list.slice(0, 250)
//
// fs.writeFile(path.join(__dirname, key + '.result.json'), JSON.stringify(list), err => {
// if (err) {
// throw err
// }
// })
// }
})