This repository has been archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
executable file
·78 lines (70 loc) · 1.96 KB
/
app.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
var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path');
var MongoStore = require('connect-mongo')(express);
var setting = require('./settings');
var mongodb = require('./models/db.js');
var cronJob = require('cron').CronJob;
var app = express();
app.set('port', process.env.PORT || 5000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser({uploadDir:'./tmp'}));
app.use(express.methodOverride());
app.use(express.static(__dirname+'/public'));
app.use(express.cookieParser());
app.use(express.session({
secret: setting.cookieSecret,
store: new MongoStore({
db:setting.db
})
})
);
app.use(app.router);
routes(app);
if('development' === app.get('env'))
app.use(express.errorHandler());
http.createServer(app).listen(app.get('port'),function(){
console.log("Express server listenning on port "+app.get('port'));
});
var job = new cronJob({
cronTime: '00 * * * 1-7',
onTick:function(){
console.log("tick");
var loc = 0;
mongodb.open(function(err, db){
if(err){
return console.log('db error');
}
db.collection('silencer', function(err, collection){
if(err){
console.log('col error');
return mongodb.close();
}
collection.update({"op":1}, {$set:{"op":0}}, {multi:true},function(err, doc){
loc = 1;
});
})
db.collection('girl', function(err, collection){
if(err){
console.log('col error');
return mongodb.close();
}
collection.find({}).toArray(function(err, doc){
doc.forEach(function(e){
if(e.plike > 1){
e.plike -= 0.1;
}
e.like = 1 + Math.sqrt(4 - 2 * (e.plike - 2));
collection.save(e);
})
mongodb.close();
})
})
})
}
})
job.start();