-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathprocesser.js
73 lines (69 loc) · 2.17 KB
/
processer.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
/**
* Process data
*/
const config = require('./config/environment')
const parseproxy = require('parseproxy')
const co = require('co')
const fs = require('fs')
const path = require('path')
const util = require('util')
parseproxy.init(config.app.serverURL, config.app.appId, config.app.javascriptKey)
const EgretWendaClass = parseproxy.getParseObject('EgretWenda')
const EgretWendaTotalQuery = parseproxy.getParseQuery(EgretWendaClass, [{
ref: 'notEqualTo',
key: 'answer_person_id',
val: null
}])
LINES_TXT = path.join(__dirname, 'egret_wenda_lines_raw.txt')
CONVERSATIONS_TXT = path.join(__dirname, 'egret_wenda_conversations_raw.txt')
co(function * () {
let totalCount = yield EgretWendaTotalQuery.count()
let questionId = 0
let lineIdIndex = 0
let conversationIdIndex = 0
for (let i = 0; i < totalCount / 1000; i++) {
const query = parseproxy.getParseQuery(EgretWendaClass, [{
ref: 'notEqualTo',
key: 'answer_person_id',
val: null
}, {
ref: 'limit',
val: 1000
}, {
ref: 'skip',
val: 1000 * i
}])
const results = yield query.find()
results.forEach(function (val) {
console.log('qid: ' + (questionId++) + ' >> ' + val.get('title'))
let lin1 = lineIdIndex++
let lin2 = lineIdIndex++
let convId = conversationIdIndex++
let title = val.get('title')
let date = val.get('date')
let url = val.get('url')
let question = val.get('question')
let question_person_id = val.get('question_person_id')
let answer_text = val.get('answer_text')
let answer_person_id = val.get('answer_person_id')
// process lines
fs.appendFileSync(LINES_TXT, util.format('%s +++$+++ %s +++$+++ %s\n',
lin1,
question_person_id,
title))
fs.appendFileSync(LINES_TXT, util.format('%s +++$+++ %s +++$+++ %s\n',
lin2,
answer_person_id,
answer_text))
// process conversations
fs.appendFileSync(CONVERSATIONS_TXT, util.format('%s +++$+++ %s +++$+++ %s +++$+++ %s +++$+++ %s +++$+++ [%d, %d]\n',
convId,
question_person_id,
answer_person_id,
date,
url,
lin1,
lin2))
})
}
})