Skip to content

Instantly share code, notes, and snippets.

@ry
Created December 12, 2011 19:27
Show Gist options
  • Save ry/1468688 to your computer and use it in GitHub Desktop.
Save ry/1468688 to your computer and use it in GitHub Desktop.
// Run this via crontab
var rss = require('rss');
var fs = require('fs');
var htmlFilename = '/home/node/web/nodejs.org/index.html';
var url = 'http://jobs.nodejs.org/a/jbb/find-jobs-rss';
var jobs = '';
var response = rss.parseURL(url, function(articles) {
for(var i = 0; i < articles.length; i++) {
var title = articles[i].title;
var link = articles[i].link;
var atIndex = title.indexOf(' at ');
if (atIndex >= 0) {
title = title.slice(atIndex + 4);
}
// Remove terminating parens.
title = title.replace(/ \(.*\)$/, '');
jobs += "<li><a href='" + link + "'>" + title + "</a></li>";
}
// Ghetto templating
jobs = '<!-- JOBS -->' + jobs + '<!-- JOBS -->';
console.log(jobs);
var html = fs.readFileSync(htmlFilename, 'utf8');
var modified = html.replace(/<!-- JOBS -->.*<!-- JOBS -->/, jobs);
fs.writeFileSync(htmlFilename, modified, 'utf8');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment