-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
67 lines (56 loc) · 1.85 KB
/
main.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
var pprint = require('./tasks/_helpers.js').pprint;
function print_usage(){
console.log([
'Usage: phantomjs --config=config.json main.js -t TASK -u EMAIL -p PASSWORD -c COOKIE_JAR',
'',
'--------------------------------------------',
'',
' -t TASK : TASK = login | friends | stories',
' -u EMAIL : your email',
' -p PASSWORD : your password',
' -c COOKIE_JAR : cookie jar in json format',
'',
].join('\n'));
}
var system = require('system');
var args = require('./node_modules/minimist/index.js')(system.args.slice(1));
//phantom.exit();
var task = args.t, CookieJar = args.c, email = args.u, password = args.p;
if (!task || !CookieJar){
console.error('Missing argument');
print_usage();
phantom.exit();
}
if (task == 'login' && (!email || !password)){
console.error('Missing argument');
print_usage();
phantom.exit();
}
var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)';
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
page.onResourceError = function(resourceError) {
page.reason = resourceError.errorString;
page.reason_url = resourceError.url;
};
var tasks = require('./tasks/tasks.js');
if (task == 'login'){
tasks.login.run(page, email, password, CookieJar, function(){
console.log("completed");
phantom.exit();
});
} else if (task == 'stories'){
var maxPages = 10;
tasks.stories.run(page, CookieJar, maxPages, function(){
console.log('completed');
phantom.exit();
});
} else if (task == 'friends'){
tasks.friends.run(page, CookieJar, function(friends){
console.log('completed');
console.log(pprint(friends));
phantom.exit();
});
}