-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
68 lines (49 loc) · 1.47 KB
/
server.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
var express = require('express');
var app = express();
var Twit = require('twit');
var T = new Twit(require('./config.js'));
app.set('port', (process.env.PORT || 5000))
app.use(express.static(__dirname + '/public'))
var styles = require('./styles');
var adjuncts = require('./adjuncts');
var hops = require('./hops');
function CreateSomethingNew() {
var MAX_LENGTH = 140;
var len = 141;
var something = '';
while (len > MAX_LENGTH) {
var style = styles[Math.floor(Math.random() * styles.length)].name;
var adjunct = adjuncts[Math.floor(Math.random() * adjuncts.length)].name;
var hop = hops[Math.floor(Math.random() * hops.length)].name;
something = style + ' with ' + adjunct + ' and ' + hop + ' hops';
len = something.length;
console.log(something + '; length: ' + len);
}
return something;
}
function tweet() {
var newbeer = CreateSomethingNew();
T.post('statuses/update', { status: newbeer }, function(err, reply) {
if (err) {
console.log('error:', err);
}
else {
console.log('reply:', reply);
}
});
}
tweet();
setInterval(function() {
try {
tweet();
}
catch (e) {
console.error(e);
}
}, 1000 * 60 * 60);
app.get('/', function (request, response) {
response.send(CreateSomethingNew());
})
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'))
})