summaryrefslogtreecommitdiffstats
path: root/main.js
blob: 7df2668f889cc0f095d8391e2c28c46f126071a9 (plain)
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
#!/usr/bin/env node

var http = require("http"),
mail = require('mail').Mail({host: 'mail'});

var config = {
    user: 'spline',
    time: 5 * 60 * 1000
};

function poll() {
    http.get(
        { host: 'api.twitter.com',
          path: '/1/users/lookup.json?screen_name=' + config.user },

        function (res) {
	    var data = '';
	    res.setEncoding('utf8');

            res.on('data', function (chunk) {
	        data = data + chunk;
            });

            res.on('end', function () {
                data = JSON.parse(data);

	        if (data.errors) {
                    mail.message({
                        from: 'alex@spline.inf.fu-berlin.de',
                        to: ['spline@spline.inf.fu-berlin.de'],
                        subject: config.user + ' auf Twitter ist frei'
                    })
                        .body('Hi,\nder ' + config.user + ' Account auf twitter wurde soeben gelöscht.\nBitte jetzt registrieren.\n\nGruß,\ntwitter-poll')
                        .send(function(err) {
                            if (err) {
                                setTimeout(poll, config.time);
                            }
                            console.log('Sent mail!');
                        });
	        }
                else {
                    console.log(new Date().toUTCString());
                    setTimeout(poll, config.time);
                }
	    });
        }
    );
}

if (module === require.main) {
    poll();
}