-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (44 loc) · 1020 Bytes
/
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
require('./verify_dep');
var util = require('util'),
phantom = require('phantom'),
events = require('events');
function GServiceMiner(url, opts){
events.EventEmitter.call(this);
opts = opts || {};
var refresh = opts.refresh || 60 * 1000; //1 minute
var self = this;
setupPage(function(ph, page){
page.open(url, function(status){
if(status === 'success') {
retrievePoints(page, refresh, function(points){
self.emit('data', {points : points});
});
}
else {
self.emit('error');
ph.exit();
}
});
});
}
function setupPage(cb){
phantom.create(function(ph){
ph.createPage(function(page){
cb(ph, page);
});
});
}
function retrievePoints(page, refresh, cb){
page.evaluate(
function(){
return returned_result;
},
function(result){
cb(result.Points);
});
setTimeout(function(){
retrievePoints(page, refresh, cb);
}, refresh);
}
util.inherits(GServiceMiner, events.EventEmitter);
module.exports = GServiceMiner;