-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacebook.js
executable file
·69 lines (67 loc) · 2.35 KB
/
facebook.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
var mongodb = require('mongodb'),
mongoserver = new mongodb.Server('localhost', 26374),
dbConnector = new mongodb.Db('uenergy', mongoserver);
var done = false;
var count = 0;
var totcount = 0;
dbConnector.open(function(err, db){
if(err){
console.log('oh shit! connector.open error!');
console.log(err);
}
else{
console.log('opened successfully');
db.createCollection('artists', function(err, artists){
if(err){
console.log('oh shit! db.createCollection error!');
console.log(err);
}
else{
console.log('artists created');
db.createCollection('songs', function(err,songs){
if(err){
console.log('songs creation error');
console.log(err);
return;
}
songs.find().each(function(err,doc){
if(err){
console.log('each error...');
console.log(err);
}
else if(doc != null){
artists.findOne({'_id':doc.song.artist_id},{'artist.foreign_ids[0].foreign_id':true},function(err,fb){
if(err){
console.log('findone facebook artists error');
console.log(err);
}
else if(fb.artist != undefined && fb.artist.foreign_ids != undefined && fb.artist.foreign_ids[0].foreign_id != undefined){
count++;
totcount++;
var facebook = 'http://facebook.com/pages/';
var fbookarr = fb.artist.foreign_ids[0].foreign_id.split(':');
facebook += fbookarr[1]+'/'+fbookarr[2];
doc.song.facebook = facebook;
songs.findAndModify({'_id':doc._id},[['_id','asc']],doc,{},function(err){
if(err){
console.log('find and modify error');
console.log(err);
}
else{
count--;
if(count == 0 && done == true){
console.log('totcount: ' + totcount);
process.exit();
}
}
});
}
});
}
else{done=true; if(count == 0){ console.log('totcount: '+totcount); process.exit();}}
});
});
}
});
}
});