get-rss-atom
Advanced tools
Comparing version 1.0.0 to 1.0.1
156
get.js
'use strict'; | ||
let hostURL = ''; | ||
exports.getRssAtom = function(feedUrl) { | ||
if (process.argv.indexOf("-url") !== -1) { | ||
hostURL = process.argv[process.argv.indexOf("-url") + 1] | ||
} | ||
const | ||
url = require('url'), | ||
feed = url.parse(feedUrl), | ||
http = require('http'), | ||
https = require('https'), | ||
options = { | ||
host: feed.hostname, | ||
port: feed.port, | ||
path: feed.path | ||
}; | ||
const | ||
url = require('url'), | ||
feed = url.parse(hostURL), | ||
http = require('http'), | ||
https = require('https'), | ||
options = { | ||
host: feed.hostname, | ||
port: feed.port, | ||
path: feed.path | ||
}; | ||
function getItem(content, tag) { | ||
let tagStart = 0, tagEnd = 0, s = '', count = 0; | ||
while (content.search('<' + tag) > 0 && count < content.length) { | ||
tagStart = content.search('<' + tag); | ||
tagEnd = content.search('/' + tag + '>'); | ||
if (tagEnd > tagStart) { | ||
s = content.substr(tagStart, tagEnd - tagStart + tag.length + 2); | ||
content = content.replace(s, '') | ||
} else { | ||
count++ | ||
} | ||
} | ||
return s.replace("<![CDATA[", "") | ||
.replace("]]>", "") | ||
.replace(/<[^>]+>/g, '') | ||
.replace(/\r?\n|\r/g, '') | ||
} | ||
function getItem(content, tag) { | ||
let tagStart = 0, tagEnd = 0, s = '', count = 0; | ||
while (content.search('<' + tag) > 0 && count < content.length) { | ||
tagStart = content.search('<' + tag); | ||
tagEnd = content.search('/' + tag + '>'); | ||
if (tagEnd > tagStart) { | ||
s = content.substr(tagStart, tagEnd - tagStart + tag.length + 2); | ||
content = content.replace(s, '') | ||
function getItemAtom(content, tag) { | ||
const match = content.match('<' + tag + '(.*)?/>'); | ||
if (match !== null) { | ||
return match[0].match(/"(.*)"/)[0].replace(/"/g, '') | ||
} else { | ||
count++ | ||
return '' | ||
} | ||
} | ||
return s.replace("<![CDATA[", "") | ||
.replace("]]>", "") | ||
.replace(/<[^>]+>/g, '') | ||
.replace(/\r?\n|\r/g, '') | ||
} | ||
function getItemAtom(content, tag) { | ||
const match = content.match('<' + tag + '(.*)?/>'); | ||
if (match !== null) { | ||
return match[0].match(/"(.*)"/)[0].replace(/"/g, '') | ||
} else { | ||
return '' | ||
function getItems(content, tag) { | ||
let arr = [], tagStart = 0, tagEnd = 0, count = 0; | ||
while (content.search('<' + tag) > 0 && count < content.length) { | ||
tagStart = content.search('<' + tag); | ||
tagEnd = content.search('/' + tag + '>'); | ||
if (tagEnd > tagStart) { | ||
let | ||
s = content.substr(tagStart, tagEnd - tagStart + tag.length + 2), | ||
t = getItem(s, 'title'), | ||
c = getItem(s, 'content').concat(getItem(s, 'description')), | ||
l = getItem(s, 'link'); | ||
if (t === '') t = '[Failed]'; | ||
if (c === '') c = '[Failed]'; | ||
if (l === '') l = getItemAtom(s, 'link'); | ||
if (l === '') l = '[Failed]'; | ||
arr.push({title: t, description: c, href: l}); | ||
content = content.replace(s, '') | ||
} | ||
count++ | ||
} | ||
return arr | ||
} | ||
} | ||
function getItems(content, tag) { | ||
let arr = [], tagStart = 0, tagEnd = 0, count = 0; | ||
while (content.search('<' + tag) > 0 && count < content.length) { | ||
tagStart = content.search('<' + tag); | ||
tagEnd = content.search('/' + tag + '>'); | ||
if (tagEnd > tagStart) { | ||
let | ||
s = content.substr(tagStart, tagEnd - tagStart + tag.length + 2), | ||
t = getItem(s, 'title'), | ||
c = getItem(s, 'content').concat(getItem(s, 'description')), | ||
l = getItem(s, 'link'); | ||
if (t === '') t = '[Failed]'; | ||
if (c === '') c = '[Failed]'; | ||
if (l === '') l = getItemAtom(s, 'link'); | ||
if (l === '') l = '[Failed]'; | ||
arr.push( { title: t, description: c, href: l } ); | ||
content = content.replace(s, '') | ||
} | ||
count++ | ||
function extractItems(content) { | ||
return getItems(content.toString(), 'item') | ||
.concat(getItems(content.toString(), 'entry')) | ||
} | ||
return arr | ||
} | ||
function extractItems(content) { | ||
return getItems(content.toString(), 'item') | ||
.concat(getItems(content.toString(), 'entry')) | ||
} | ||
const parser = function (res) { | ||
let content = '', count = 0; | ||
res.on('data', chunk => content += chunk); | ||
res.on('end', () => { | ||
extractItems(content).forEach((item) => { | ||
count++; | ||
console.log(`\n--${count}-- ${item.title}\n${item.description}\n${item.href}\n`) | ||
}) | ||
}); | ||
console.log(`Got response: ${res.statusCode}`) | ||
}; | ||
const parser = function(res) { | ||
let content = '', count = 0; | ||
res.on('data', chunk => content += chunk); | ||
res.on('end', () => { | ||
extractItems(content).forEach((item) => { | ||
count++; | ||
console.log(`\n--${count}-- ${item.title}\n${item.description}\n${item.href}\n`) | ||
if (feed.port === '80') { | ||
http.get(options, parser).on('error', e => { | ||
console.error(e.message) | ||
}) | ||
}); | ||
console.log(`Got response: ${res.statusCode}`) | ||
} else { | ||
https.get(options, parser).on('error', e => { | ||
console.error(e.message) | ||
}) | ||
} | ||
}; | ||
if (feed.port === '80') { | ||
http.get(options, parser).on('error', e => { | ||
console.error(e.message) | ||
}) | ||
} else { | ||
https.get(options, parser).on('error', e => { | ||
console.error(e.message) | ||
}) | ||
} |
{ | ||
"name": "get-rss-atom", | ||
"version": "1.0.0", | ||
"description": "", | ||
"version": "1.0.1", | ||
"description": "Get RSS from URL and return JSON (not ready yet)", | ||
"main": "get.js", | ||
@@ -9,5 +9,5 @@ "scripts": { | ||
}, | ||
"author": "", | ||
"author": "Niels Koster", | ||
"license": "ISC", | ||
"dependencies": {} | ||
} |
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
3721
5
2