summaryrefslogtreecommitdiffstats
path: root/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'main.js')
-rwxr-xr-xmain.js63
1 files changed, 45 insertions, 18 deletions
diff --git a/main.js b/main.js
index dda62ba..600c34e 100755
--- a/main.js
+++ b/main.js
@@ -1,25 +1,52 @@
#!/usr/bin/env node
-var http = require("http");
+var http = require("http"),
+email = require('mailer');
-http.get(
- { host: 'api.twitter.com',
- path: '/1/users/lookup.json?screen_name=spline' },
+function poll() {
+ http.get(
+ { host: 'api.twitter.com',
+ path: '/1/users/lookup.json?screen_name=spline' },
- function (res) {
- var data = '';
- res.setEncoding('utf8');
+ function (res) {
+ var data = '';
+ res.setEncoding('utf8');
- res.on('data', function (chunk) {
- data = data + chunk;
- });
+ res.on('data', function (chunk) {
+ data = data + chunk;
+ });
- res.on('end', function () {
- data = JSON.parse(data);
+ res.on('end', function () {
+ data = JSON.parse(data);
- if (data.errors) {
- console.log('User not found!');
- }
- });
- }
-);
+ if (data.errors) {
+ email.send(
+ {
+ host : "mail",
+ port : "25",
+ domain : "localhost",
+ to : "alex@animux.de",
+ from : "alex@spline.inf.fu-berlin.de",
+ subject : "spline auf Twitter ist frei",
+ body: "Hi,\nder spline account auf twitter wurde soeben gelöscht.\nBitte jetzt registrieren.\n\nGruß,\ntwitter-poll"
+ },
+
+ function(err, result){
+ if(err){
+ console.log(err);
+ setTimeout(poll, 5 * 60 * 1000);
+ }
+ });
+ }
+ else {
+ console.log(new Date().toUTCString());
+ setTimeout(poll, 5 * 60 * 1000);
+ }
+ });
+ }
+ );
+}
+
+if (module === require.main) {
+ poll();
+}