Skip to content
Permalink
Browse files
fix bugs
  • Loading branch information
robertkowalski committed Feb 16, 2015
1 parent b456c03 commit db84dab079108366dcdbe70cbe12e1c1cc97abb7
Showing 4 changed files with 24 additions and 20 deletions.
@@ -15,7 +15,7 @@ const crawler = require('./lib/index.js'),
argument = require('./lib/argument.js');

const arg = process.argv[2];
const template = '{{count}} {{messages}} since {{month}} ' +
const template = '{{count}} {{messages}} since end of {{month}} ' +
'({{diff}} change)';

if (arg === '-h' || arg === '--help') {
@@ -41,7 +41,7 @@ crawler(queryParams, monthsForDiff, function (err, data) {

logLine('Your message counts:');
Object.keys(data).forEach(function (el) {
const month = argument.getMonthAsWordFromNow(arg, monthsForDiff),
const month = argument.getMonthAsWordFromNow(arg, monthsForDiff + 1),
messageCount = data[el].curr,
message = messageCount > 1 ? 'messages' : 'message',
wikitext = template
@@ -14,6 +14,7 @@ const moment = require('moment');

exports.prepareQueryParams = prepareQueryParams;
function prepareQueryParams (arg) {
console.log(arg)
const startEnd = getStartEndDates(arg, 3);
startAsString = startEnd[0].format('YYYYMM'),
diffStartEnd = getStartEndDates(startAsString, 3);
@@ -50,6 +51,7 @@ function getMonthAsWordFromNow (reportEnd, time) {
return moment(inter, 'YYYYMM').format('MMMM');
}

exports.getMonthAsWord = getMonthAsWord;
function getMonthAsWord (reportEnd) {
return moment(reportEnd, 'YYYYMM').format('MMMM');
}
@@ -60,8 +62,7 @@ function formatQuery (startEnd) {
}

function getStartEndDates (arg, time) {
const end = moment(arg, 'YYYYMM'),
const end = moment(arg, 'YYYYMM').subtract(1, 'month'),
start = moment(arg, 'YYYYMM').subtract(time, 'months');

return [start, end];
}
@@ -16,8 +16,9 @@ const async = require('async'),
assert = require('assert'),
argument = require('./argument.js');

const urlTemplate = 'http://markmail.org/search/?q=list%3A' +
'org.apache.{{listname}}%20date%3A{{date}}';
const urlPrefix = 'http://markmail.org/search/?q=list%3Aorg.apache.';
const urlTemplate = urlPrefix + '{{listname}}%20date%3A{{date}}';


const lists = [
'couchdb-announce',
@@ -40,9 +41,6 @@ function api (queryParams, timeframe, cb) {
const listUrlsCurr = getUrls(queryParams.queryCurr),
listUrlsDiff = getUrls(queryParams.queryDiff);

console.log(listUrlsCurr);
console.log(listUrlsDiff);

async.parallel({
current: function (cb) {
getMessageCounts(listUrlsCurr, cb);
@@ -86,7 +84,7 @@ function pick (element, structure) {
}

function getDiffString (count, countOld) {
const result = normalize(countOld) - normalize(count);
const result = normalize(count) - normalize(countOld);

if (result >= 0) {
return '+' + result;
@@ -95,6 +93,9 @@ function getDiffString (count, countOld) {
}

function normalize (string) {
if (!string) {
string = '0';
}
return parseInt(string.replace(',', ''), 10);
}

@@ -113,21 +114,23 @@ function requestWithOptions (url, cb) {
maxSockets: Infinity
}
}, function (err, res, body) {
cb(err, body);
cb(err, [url, body]);
})
}

function normalizeListName (list) {
return list.replace(urlPrefix, '').split('%20date')[0];
}

function getMessageCounts (urlList, cb) {
async.map(urlList, requestWithOptions, function (err, results) {
if (err) {
return cb(err);
}

const res = results.map(function (markup) {
const $ = cheerio.load(markup),
const res = results.map(function (element) {
const $ = cheerio.load(element[1]),
count = $('#lists .count').text(),
list = $('#lists a').text().replace('org.apache.couchdb.', '');

list = normalizeListName(element[0]);
return [list, count];
});

@@ -29,14 +29,14 @@ describe('arguments', function () {
it('prepares query parameters', function () {
const queryParams = argument.prepareQueryParams('201411');

assert.equal(queryParams.queryCurr, '201408-201411');
assert.equal(queryParams.queryDiff, '201405-201408');
assert.equal(queryParams.queryCurr, '201408-201410');
assert.equal(queryParams.queryDiff, '201405-201407');
});

it('prepares urls for the current and the diff', function () {
const queryParams = argument.prepareQueryParams('201411');

assert.equal(queryParams.queryCurr, '201408-201411');
assert.equal(queryParams.queryDiff, '201405-201408');
assert.equal(queryParams.queryCurr, '201408-201410');
assert.equal(queryParams.queryDiff, '201405-201407');
});
});

0 comments on commit db84dab

Please sign in to comment.