-
Notifications
You must be signed in to change notification settings - Fork 0
/
nwm.js
executable file
·125 lines (115 loc) · 3.46 KB
/
nwm.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
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
#!/usr/bin/env node
/**
* This file is part of bbNightWatchman
*
* Copyright (C) 2011 Clochix.net
*
* Keskispas is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* bbNightWatchman is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
/**
* Usage
* nwm.js -n 20 get toto : get 20 tweets about toto
* nwm.js long : convert short urls to real
* nwm.js readability : parse document with readability
* nwm.js viewtext : parse document with viewtext
*/
GLOBAL.DEBUG = true;
var nwm = require('./lib/nwm');
var tc = require('./lib/tweets_collection');
var dc = require('./lib/documents_collection');
var cli = require('cli').enable('status'); // https://github.com/chriso/cli
var config = require('./config');
var mongodb = require("mongodb");
var util = require("util");
var db = new mongodb.Db('veille', new mongodb.Server("127.0.0.1", 27017, {}));
function debug(o) {
console.log(util.inspect(o, true, null));
}
// Options: long_tag: [short_tag, description, value_type, default_value]
cli.parse({
num: ['n', 'Number of tweets to fetch', 'number', 5]
},
['get', 'long', 'resolve', 'test', 'readability', 'viewtext', 'calais']
);
switch (cli.command) {
case 'get':
if (cli.args.length !== 1) {
cli.error("get tag");
} else {
cli.debug('Fetching tweets');
var t = new tc.TweetsCollection(db);
var d = new dc.DocumentsCollection(db);
t.search(cli.args[0], cli.options.num, function(){
t.getRealUrls(function(){
d.update('reada', 'getReadability', function(){
d.update('viewtext', 'getViewText', function(){
d.update('calais', 'getCalais', function(){
});
});
});
});
});
}
break;
case 'long':
cli.debug('Resolving short urls');
var t = new tc.TweetsCollection(db);
t.getRealUrls();
break;
case 'resolve':
nwm.getRealUrl(cli.args[0], function(long_url){cli.info(long_url)});
break;
case 'readability':
var d = new dc.DocumentsCollection(db);
d.update('reada', 'getReadability');
break;
case 'viewtext':
var d = new dc.DocumentsCollection(db);
d.update('viewtext', 'getViewText');
break;
case 'calais':
var d = new dc.DocumentsCollection(db);
d.update('calais', 'getCalais');
break;
case 'test':
var alchemy = require('./lib/alchemy.js');
alchemy = new alchemy(config.data.alchemy);
alchemy.get(cli.args[0], function(res){debug(res);});
/*
db.open(function(err, db) {
db.collection('documents', function(err, collection) {
collection.findOne({}, function(err, doc) {
Document.prototype.getCalais(doc, function(obj){debug(obj);db.close();});
});
});
});
*/
break;
default:
break;
}
/*
db.open(function(err, db) {
db.collection('tweets', function(err, collection) {
collection.find({}, function(err, cursor) {
cursor.each(function(err, doc){
var updated = false;
if (doc && doc.urls) {
doc.urls.forEach(function(u, i) {
getDocument(u);
});
}
});
});
});
});
*/