Comparing version 2.2.0 to 2.2.1
#! /usr/bin/env node | ||
/* eslint-env node */ | ||
/* eslint no-console:0 */ | ||
'use strict'; | ||
const http = require('http'); | ||
const colour = require('colour'); | ||
let justNuCount = 0 | ||
, justNuTopics = []; | ||
console.log(colour.yellow(' --------------------- ')); | ||
console.log(colour.yellow(' A F T O N B L A D E T ')); | ||
console.log(colour.yellow(' --------------------- ')); | ||
console.log('\n'); | ||
/** | ||
@@ -35,3 +25,3 @@ * Find number of "JUST NU:" in a string. | ||
const parts = text.split('<span'); | ||
let subtitles = []; | ||
const subtitles = []; | ||
@@ -106,41 +96,26 @@ function containsArrow (str) { | ||
/** | ||
* Prints to console. | ||
* | ||
* @param {Number} count - Number of "JUST NU :"s to reportAndClose | ||
* @param {String[]} topics - Array of topics as strings to list in console. | ||
*/ | ||
function reportAndClose (count, topics) { | ||
console.log(colour.white(` Antal ${'JUST NU'.bold} just nu:`), colour.cyan(count)); | ||
module.exports = function (callback) { | ||
let justNuCount = 0 | ||
, justNuTopics = [] | ||
; | ||
console.log('\n'); | ||
http.request({ host: 'www.aftonbladet.se' }, res => { | ||
res.setEncoding('utf8'); | ||
for (let topic of topics) { | ||
let header = 'JUST NU:'.red.bold; | ||
res.on('data', chunk => { | ||
let count = getJustNuCount(chunk); | ||
console.log(` ${header} ${topic.header}`); | ||
if (count > 0) { | ||
justNuCount += count; | ||
justNuTopics = justNuTopics.concat(getTopics(chunk)); | ||
} | ||
}); | ||
for (let subtitle of topic.subtitles) { | ||
let symbol = colour.red(subtitle.symbol); | ||
console.log(` ${symbol} ${subtitle.subtitle}`); | ||
} | ||
} | ||
process.exit(0); | ||
} | ||
http.request({ host: 'www.aftonbladet.se' }, res => { | ||
res.setEncoding('utf8'); | ||
res.on('data', chunk => { | ||
let count = getJustNuCount(chunk); | ||
if (count > 0) { | ||
justNuCount += count; | ||
justNuTopics = justNuTopics.concat(getTopics(chunk)); | ||
} | ||
}); | ||
res.on('end', () => reportAndClose(justNuCount, justNuTopics)); | ||
}).end(); | ||
res.on('end', () => { | ||
const count = justNuCount; | ||
const topics = justNuTopics; | ||
callback({ count, topics }); | ||
}); | ||
}).end(); | ||
}; |
{ | ||
"name": "just-nu", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Antal JUST NU på Aftonbladet", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32029
9
97