Skip to content

Instantly share code, notes, and snippets.

@katat
Last active February 20, 2016 08:26
Show Gist options
  • Save katat/fb9bb08b027e567c6fc6 to your computer and use it in GitHub Desktop.
Save katat/fb9bb08b027e567c6fc6 to your computer and use it in GitHub Desktop.
Hack the use of the topcoder API to get the latest challenge data, and create RSS string in the desired format to be consumable in any RSS reader.
'use latest';
var request = require('request@2.56.0');
var xmlbuilder = require('xmlbuilder@2.6.4');
module.exports = function(context, req, res) {
request({
method: 'GET',
uri: 'https://api.topcoder.com/v2/challenges/active?review=COMMUNITY,INTERNAL&type=develop'
}, function(error, response, body) {
var rss = xmlbuilder.create({
'rss': {
'@version': 2.0
}
});
var channel = rss.ele({
channel: {
'title': 'title',
'link': 'http://link.com',
'description': 'desc',
'category': 'cat'
}
});
var challenges = JSON.parse(body).data;
challenges.sort(function(a, b) {
return new Date(b.registrationStartDate) - new Date(a.registrationStartDate);
});
challenges.forEach(function(challenge) {
var item = channel.ele('item');
item.ele('title', challenge.challengeName + ' - $' + challenge.totalPrize);
var description = 'Type: ' + challenge.challengeType + '|\n' +
'Registrants: ' + challenge.numRegistrants + '|\n' +
'Current Phrase: ' + challenge.currentPhaseName + '|\n' +
'Submission End: ' + challenge.submissionEndDate + '|\n';
item.ele('description', description);
item.ele('link', 'https://www.topcoder.com/challenge-details/' + challenge.challengeId);
item.ele('pubDate', challenge.registrationStartDate);
challenge.technologies.forEach(function(tech) {
item.ele('category', tech);
});
});
var xml = channel.doc().end({pretty: true});
res.writeHead(200, { 'Content-Type': 'application/xml '});
res.end(xml);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment