-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
92 lines (69 loc) · 2.38 KB
/
test.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
token="CAACEdEose0cBAMMFSHOJzLkgu1ZBhlcXhkoxehSnodXDKDRDYIWcg0Lba7OI1ZCU8LW7b1sgb3ltBxncISTmkm4O39yKUTXAJ8dgUPYCiql1lERogWXGxjCIbw7xZCkEhxqSBa1MLrrQObnSNHCvQbRNZAkC4lY020xsFAl2jpsV0h6EPzLRpA6Nvch0XBg33ZBnZCdXjzuAZDZD";
var graph = require('fbgraph');
graph.setAccessToken(token);
var ids=[];
var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;
var url = 'mongodb://cloudman:[email protected]:43714/fb';
var feeds;
var ids=[];
var mongoose = require('mongoose');
mongoose.connect('mongodb://cloudman:[email protected]:43714/fb');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
// we're connected!
});
var ActivitySchema = mongoose.Schema({
page: String,
feed: String,
id: String,
likes : Number,
cmt : Number
});
ActivitySchema.methods.addlike = function () {
if(this.likes==0)this.likes=1;
console.log(this.count);
}
var act = mongoose.model('act', ActivitySchema);
function recuperer(feedID,id,count){
url=feedID+"/likes";
var arr = feed.split("_");
pageID=arr[0];
graph.get(url, function(err, res) {
if(!err){
//console.log(res.data);
res.data.forEach(function(item) {
id.push(item.id);
});
//id.push(res.data);
console.log(id);
if (res.paging.next && count>0) {
setTimeout(recuperer(res.paging.next,id,count-1),10000);
} else {
MongoClient.connect(url, function (err, db) {
if(err){
console.log("erreur de connexion à la base de données");
}else{
console.log(id.length)
id.forEach(function(item){
act.findOne({ page : pageID ,feed : feedID ,id : item }, function (err, u) {
if (err) return handleError(err);
if (u) {
console.log ('user ' , item , ' already commeted feed ', doc.feed);
u.likes=1;
u.save();
}else{
var a = new act({page: pageID , feed : doc.feed ,id : item , likes : 1 , cmt : 0} ) ;
a.save();
}
});
});//end forEach
db.close();
}
});
} /// end else
}
});
};
recuperer("346593403645_10154132322828646",ids,20);