#!/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(); }