Skip to content

Instantly share code, notes, and snippets.

@Pita
Created April 17, 2012 10:34
Show Gist options
  • Save Pita/2405170 to your computer and use it in GitHub Desktop.
Save Pita/2405170 to your computer and use it in GitHub Desktop.
Gumtreebot
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 = ["person1@example.com", "person2@example.com"];
emails.forEach(function(email){
var mailOptions = {
from: "gumtreebot@example.com",
to: email,
subject: "GUMTREE: " + title,
text: link + "\n\n\n" + content
}
transport.sendMail(mailOptions);
});
} catch(e){
console.error(e.stack || e);
}
});
});
});
*/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