Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Added comments for the "New" parsers.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsergio committed Jul 12, 2014
1 parent c67dc84 commit b926ffe
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function YComb(callback){
request('https://news.ycombinator.com', function(error, response, html){
if(!error && response.statusCode === 200){
var metadataArray = [ ];
var YCOMB_COMMENT_URL = "https://news.ycombinator.com/"
var $ = cheerio.load(html);
$('span.comhead').each(function(i, element){
var a=$(this).prev(); //selects previous data
Expand All @@ -28,6 +27,8 @@ function YComb(callback){
var subtext = a.parent().parent().next().children('.subtext').children(); // gets the subtext from the children
var points = $(subtext).eq(0).text();
var username = $(subtext).eq(1).text();

var YCOMB_COMMENT_URL = "https://news.ycombinator.com/"
var comments = $(subtext).eq(2).text();
var comments_link = YCOMB_COMMENT_URL + $(subtext).eq(2).attr('href');

Expand Down Expand Up @@ -68,15 +69,21 @@ function Lobster(callback){
var $ = cheerio.load(html);
$('span.link').each(function(i, element){
var a=$(this); //selects previous data
var comments_label = a.parent().children('.byline').children('span.comments_label');
var comments_link = comments_label.children('a').attr("href");
var comments = comments_label.text().match("[0-9]+") || [0];
var url=a.children().attr('href'); // parses href attribute from "a" element
var title=a.text(); // parses link title

// Note: There currently (2014-07-12) is no comments tag to be parsed
// available by scraping the Loste.rs webpage.
// This means 0 comments will have no link to the comment page.
var comments_label = a.parent().children('.byline').children('span.comments_label');
var comments_link = comments_label.children('a').attr("href");
var commentsMatch = comments_label.text().match("[0-9]+");
var comments = commentsMatch !== null ? commentsMatch[0] : 0;

var metadata = { // creates a new object
title:title,
url:url,
comments:comments[0],
comments:comments,
comments_link:comments_link
};
metadataArray.push(metadata); // pushes the object
Expand Down Expand Up @@ -157,15 +164,19 @@ function YCombNew(callback){
var subtext = a.parent().parent().next().children('.subtext').children(); // gets the subtext from the children
var points = $(subtext).eq(0).text();
var username = $(subtext).eq(1).text();

var YCOMB_COMMENT_URL = "https://news.ycombinator.com/"
var comments = $(subtext).eq(2).text();
var comments_link = YCOMB_COMMENT_URL + $(subtext).eq(2).attr('href');

var metadata = { // creates a new object
rank: parseInt(rank),
title:title,
url:url,
points: parseInt(points),
username: username,
comments: parseInt(comments)
comments: parseInt(comments),
comments_link:comments_link
};
metadataArray.push(metadata); // pushes the object
});
Expand Down Expand Up @@ -197,9 +208,21 @@ function LobsterNew(callback){
var a=$(this); //selects previous data
var url=a.children().attr('href'); // parses href attribute from "a" element
var title=a.text(); // parses link title

// Note: There currently (2014-07-12) is no comments tag to be parsed
// available by scraping the Loste.rs webpage.
// This means 0 comments will have no link to the comment page.
var comments_label = a.parent().children('.byline').children('span.comments_label');
var comments_link = comments_label.children('a').attr("href");
var commentsMatch = comments_label.text().match("[0-9]+");
var comments = commentsMatch !== null ? commentsMatch[0] : 0;

var metadata = { // creates a new object
title:title,
url:url,
comments:comments,
comments_link:comments_link

};
metadataArray.push(metadata); // pushes the object
});
Expand Down Expand Up @@ -233,9 +256,15 @@ function RProgNew(callback){
var title=a.text();
var url=a.attr('href');

var comments_tag = a.parent().parent().children('.flat-list').children('li.first').children('a');
var comments_link = comments_tag.attr("href");
var comments = parseInt(comments_tag.text());

var metadata = {
title:title,
url:url
url:url,
comments:comments,
comments_link:comments_link
};

metadataArray.push(metadata);
Expand Down

0 comments on commit b926ffe

Please sign in to comment.