Created
April 17, 2012 10:34
-
-
Save Pita/2405170 to your computer and use it in GitHub Desktop.
Gumtreebot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require("request"); | |
var parser = require("xml2json"); | |
var db = require("dirty")("db.db"); | |
var nodemailer = require("nodemailer"); | |
var transport = nodemailer.createTransport("Sendmail"); | |
db.on('load', function() { | |
request('http://www.gumtree.com/rssfeed/single-room-flatshare/shoreditch', function (err, response, body) { | |
if(err){ | |
throw err; | |
} | |
var json = JSON.parse(parser.toJson(body)); | |
var items = json.rss.channel.item; | |
items.forEach(function(item){ | |
try { | |
var title = item.title; | |
var price = /([0-9]+)pw$/.exec(title)[1]; | |
var content = item["content:encoded"].replace(/\&\#[0-9]+;/g," "); | |
var link = item.link; | |
if(price < 150){ | |
return; | |
} | |
if(db.get(link) === true){ | |
return; | |
} | |
db.set(link, true); | |
var emails = ["[email protected]", "[email protected]"]; | |
emails.forEach(function(email){ | |
var mailOptions = { | |
from: "[email protected]", | |
to: email, | |
subject: "GUMTREE: " + title, | |
text: link + "\n\n\n" + content | |
} | |
transport.sendMail(mailOptions); | |
}); | |
} catch(e){ | |
console.error(e.stack || e); | |
} | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*/5 * * * * /opt/node/bin/node /home/pita/Code/gumtreebot/bot.js > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment