Created
December 12, 2011 19:27
-
-
Save ry/1468688 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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