Skip to content

Instantly share code, notes, and snippets.

@meandavejustice
Created October 27, 2015 17:52
Show Gist options
  • Save meandavejustice/0413ddcd65741bd3e54b to your computer and use it in GitHub Desktop.
Save meandavejustice/0413ddcd65741bd3e54b to your computer and use it in GitHub Desktop.
var h = require('hyperscript');
var CronJob = require('cron').CronJob;
var nodemailer = require('nodemailer');
var craigslist = require('node-craigslist');
var options = {
category : 'cta',
maxAsk : '9000',
minAsk : '1000'
};
var users = ["[email protected]", "[email protected]"];
var client = craigslist({
city : 'portland'
});
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: '*GMAILUSERNAME*',
pass: '*PASSWORD*'
}
});
function listingTemp(l) {
return h('li',
h('a', {href: l.url}, l.title + " "),
h('span', "haspic? : " + (l.hasPic ? "✔" : "⌧")),
h('span', "location : " + l.location),
h('span', "$$ : " + l.price)
)
}
function template(listings, d) {
return h('div',
h('h1', 'Westfalia update for ' + d),
h('ul',
listings.map(listingTemp)
),
h('p', 'i ♥ you kymberly')
).innerHTML;
}
function searchCraiglist(cb) {
client.search(options, 'westfalia', cb);
}
function sendMail(options) {
transporter.sendMail(options, function(error, info){
if (error) {
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
}
function runJob() {
var d = new Date().toDateString();
searchCraiglist(function(err, listings) {
sendMail({
from: 'Watchfalia service ☭ ☭ <[email protected]>',
to: users.join(','),
subject: 'Watchfalia update for ' + d,
text: 'Westfalia raw for ' + d + ': ' +JSON.stringify(listings, null, 2),
html: template(listings, d)
})
});
}
new CronJob('00 30 11 * * 1-5', runJob, null, true, 'America/Los_Angeles');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment