-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter.js
More file actions
140 lines (109 loc) · 2.46 KB
/
twitter.js
File metadata and controls
140 lines (109 loc) · 2.46 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
"use strict";
var coffeescript = require('coffee-script/register')
var ChatHelper = require("./chathelper").ChatHelper;
var fs = require("fs")
var request = require('request')
var jsdom = require('jsdom');
var path = require('path');
var jqueryPath=path.join(__dirname,"jquery.js");
if (fs.accessSync(jqueryPath)) {
console.log(jqueryPath+" not exits,exit");
return;
}
var jquery = fs.readFileSync(jqueryPath,"utf-8");
var users=[
{
name:"破娃酱",
link:"breakwa11"
},
{
name:"贝带劲",
link:"beidaijin"
},
{
name:"刘晓原律师",
link:"liu_xiaoyuan"
},
{
name:"刘亦菲",
link:"LiuYiFeiOff"
},
{
name:"Shadowrocket",
link:"ShadowrocketApp"
},
{
name:"Victoria Raymond",
link:"projectv2ray"
},
{
name:"王思想",
link:"wangxy1"
}
];
function extract(user,$,chatController){
var allTweets= $("li.js-stream-item div.content");
for (var i=0; i<allTweets.length;++i){
var timeNode = $("span[data-time]",allTweets[i]);
var timeMs=timeNode.data("time-ms");
var contentNode = $("p.js-tweet-text,tweet-text",allTweets[i]);
var content = contentNode.text();
if (timeMs!="" && content !="") {
chatController.addMessage({
body:user.name+":"+content,
date_added:timeMs
});
}
}
}
function jsdomWrapper(user,chatController,callback){
var url ="https://twitter.com/"+user.link;
console.log("accessing ",url);
jsdom.env({
url:url,
src:[jquery],
done:function(err,window){
if (err) {
console.log(err);
if(window){
window.close();
}
callback();
return;
}
console.log(url," getted, extract it");
extract(user,window.$,chatController);
window.close();
callback();
}
});
}
function recursiveAsLoop(i,chatController,finishCallback){
if (i>=users.length) {
finishCallback();
return;
}
jsdomWrapper(users[i],chatController,function(){
recursiveAsLoop(i+1,chatController,finishCallback);
});
}
function collectFunc(chatController){
recursiveAsLoop(0,chatController,function(){
//not store history data,no need to recycle
chatController.save();
})
}
new ChatHelper(
{
addr:"16mQo7Q449ZHkqjjqJeP7dXM3xnEuczxsr",
host:"127.0.0.1",
port:43110,
proto:{
ws:"ws",
http:"http"
}
},
["zeroid.bit","web","telegrambot","1My4AHpEjVQB1Jvetpiuha7o2QtQgWHL5L"]
,false,
collectFunc);
var users