Comparing version 1.0.3 to 2.0.0
#! /usr/bin/env node | ||
const http = require("http"); | ||
/* eslint-env node */ | ||
/* eslint no-console:0 */ | ||
const options = { | ||
host: 'www.aftonbladet.se', | ||
port: 80 | ||
}; | ||
const http = require('http'); | ||
const colour = require('colour'); | ||
let justNu = 0; | ||
let justNuCount = 0 | ||
, justNuTopics = []; | ||
function getJustNuCount (string) { | ||
return (string.match(/JUST NU:/g) || []).length; | ||
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'); | ||
/** | ||
* Find number of "JUST NU:" in a string. | ||
* | ||
* @param {String} text - String to search in | ||
* @return {Number} - Occurances found. | ||
*/ | ||
function getJustNuCount (text) { | ||
return (text.match(/JUST NU:/g) || []).length; | ||
} | ||
function reportAndClose() { | ||
console.log('Antal "JUST NU" just nu:', justNu); | ||
/** | ||
* Finds multiple "JUST NU" in a string and returns them in an array. | ||
* | ||
* @param {String} text - String to search in | ||
* @return {String[]} - Array of topics found. | ||
*/ | ||
function saveTopic (text) { | ||
const justNus = text.split(/JUST NU:/g); | ||
let arr = []; | ||
for (let justNu of justNus) { | ||
if (justNu.indexOf('</span>') !== -1 && justNu.indexOf('</h2>') !== -1) { | ||
let topic = justNu.split('</span>')[1].split('</h2>')[0]; | ||
if (topic.indexOf('<') === -1) { | ||
arr.push(topic); | ||
} | ||
} | ||
} | ||
return arr; | ||
} | ||
/** | ||
* 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" just nu:'), colour.cyan(count)); | ||
console.log('\n'); | ||
for (let topic of topics) { | ||
console.log(' ' + colour.red('√') + topic.toUpperCase()); | ||
} | ||
process.exit(0); | ||
} | ||
const req = http.request(options, (res) => { | ||
http.request({ host: 'www.aftonbladet.se' }, res => { | ||
res.setEncoding('utf8'); | ||
res.on('data', (chunk) => { | ||
justNu += getJustNuCount(chunk); | ||
res.on('data', chunk => { | ||
let count = getJustNuCount(chunk); | ||
if (count > 0) { | ||
justNuCount += count; | ||
justNuTopics = justNuTopics.concat(saveTopic(chunk)); | ||
} | ||
}); | ||
res.on('end', reportAndClose); | ||
}); | ||
req.end(); | ||
res.on('end', () => reportAndClose(justNuCount, justNuTopics)); | ||
}).end(); |
{ | ||
"name": "just-nu", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"description": "Antal JUST NU på Aftonbladet", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "eslint *.js", | ||
"start": "node just-nu" | ||
@@ -23,3 +24,10 @@ }, | ||
"url": "https://github.com/enjikaka/just-nu.git" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.3.0", | ||
"eslint-config-tidal": "^1.0.3" | ||
}, | ||
"dependencies": { | ||
"colour": "^0.7.1" | ||
} | ||
} |
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
Network access
Supply chain riskThis module accesses the network.
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
3621
6
64
1
2
+ Addedcolour@^0.7.1
+ Addedcolour@0.7.1(transitive)