-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentity_crawler.js
100 lines (74 loc) · 2.17 KB
/
entity_crawler.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
/*
run an entity server side. The output may vary, depending on arguments, but probably is either nothing, error message, or entity data
- mostly the point is to run all the widgets, update their data, etc.
- and this is an important component of a crawler.
*/
console.log("starting");
var argv = require('minimist')(process.argv.slice(2));
var entityIdTemplate = argv._[0]; // format url/{{id}}
var startid = argv._[1];
var endid = argv._[2];
console.log(argv);
console.log(entityIdTemplate);
console.log("ID start: " + startid);
console.log("ID End: " +endid);
// requireses
var urlparser = require("url");
var pathparser = require("path");
var async = require("async");
// set up globals
GLOBAL = {};
GLOBAL.context = "server";
GLOBAL.params = {
root_dir : __dirname,
require_prefix : __dirname
};
var jsdom = require('jsdom');
var $;
jsdom.env({
html: "<html><body></body></html>",
scripts: [
'http://code.jquery.com/jquery-1.5.min.js'
],
done : function (err, window) {
$ = window.jQuery;
GLOBAL.$ = $;
crawl_entities(startid, endid);
}
});
var EntityManager = require(GLOBAL.params.root_dir+"/classes/entity/entity.js").EntityManager();
function crawl_entities(startid, endid){
console.log("in crawl_entities " + startid + " to " + endid);
var currentid = startid;
async.whilst(
function(){return currentid <= endid},
function(callback){
var entityId = entityIdTemplate.replace(/\{\{id\}\}/, currentid);
console.log("calling " + entityId);
function callback2(entity){
entity.addListener("allWidgetsRan", function(params){
console.log("got entity");
console.log(params.thing);
console.log(params.thing.widgetInstances);
console.log("done now?");
});
}
console.log("calling with " + currentid);
try{
EntityManager.generateEntity(entityId, callback2);
}catch(exception){
console.log("got error ");
console.log(exception);
}
currentid++;
callback();
},
function(err){
if(err){
console.log("error");
console.log(err);
}
}
);
}
console.log("done with crawler");