From 9fcb85992b9a27db04b115c753bc6b3d7c632d63 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Tue, 26 Apr 2016 10:06:09 +0100 Subject: [PATCH] adding some extras to filtering --- server/keeper.js | 270 ++++++++++++++++++++++------------------------- views/pocket.ejs | 7 +- 2 files changed, 131 insertions(+), 146 deletions(-) diff --git a/server/keeper.js b/server/keeper.js index 88e7670..810fac5 100644 --- a/server/keeper.js +++ b/server/keeper.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; /** * Created by Martin on 22/02/2016. */ @@ -8,7 +8,7 @@ var http = require('http'), request = require('request'), cheerio = require( var jsonfile = require('jsonfile'), fs = require('fs'), STRING = require( 'string'); var converter = require('html-to-markdown'); -var zlib = require("zlib"); +var zlib = require('zlib'); var log4js = require('log4js'); var logger = log4js.getLogger(); var URL = require('url'); @@ -36,19 +36,19 @@ var generics = [ ]; var specialHandlers = [{ - url: 'www.reddit.com', fn: function (body, url) { + url: 'www.reddit.com', fn: function(body, url) { return doReddit(body, url); } }, { - url: 'developer.android.com', fn: function (body, url) { - return doAndroidDeveloper(body, url); - } + url: 'developer.android.com', fn: function(body, url) { + return doAndroidDeveloper(body, url); + } }, { - url: 'www.engadget.com', fn: function (body, url) { - return doEngadget(body, url); - } + url: 'www.engadget.com', fn: function(body, url) { + return doEngadget(body, url); + } } @@ -87,7 +87,9 @@ function cleaner(b) { '#recipe-related-videos', '#tnav', '.footer', - '#tb-wrapper' + '#tb-wrapper', + '#comments', + '#menu' ]; @@ -100,8 +102,8 @@ function cleaner(b) { function insertBookmark(obj) { logger.debug('Inserting into couch...'); - // logger.info(util.inspect(obj)); - dbCouch.insert(obj, function (err, body, header) { + // Logger.info(util.inspect(obj)); + dbCouch.insert(obj, function(err, body, header) { if (err) { logger.error('Error inserting into couch'); return; @@ -116,51 +118,51 @@ function updateBookmark(obj, _id, _rev) { _obj._id = _id; _obj._rev = _rev; - dbCouch.insert(_obj, function (err, body, header) { + dbCouch.insert(_obj, function(err, body, header) { if (err) { logger.error('Error updating into couch'); return; } else { logger.info('I think we updated ok...'); - busEmitter.emit("updateTagsDB"); + busEmitter.emit('updateTagsDB'); } }); logger.debug('Update done..'); } var doInsertBookmark = (obj) => { - // logger.info('sendSocket: ' + JSON.stringify(obj)); + // Logger.info('sendSocket: ' + JSON.stringify(obj)); insertBookmark(obj); }; var doUpdateBookmark = (obj, _id, _rev) => { - // logger.info('sendSocket: ' + JSON.stringify(obj)); + // Logger.info('sendSocket: ' + JSON.stringify(obj)); updateBookmark(obj, _id, _rev); }; var doGetBookmark = (obj) => { - // logger.info('sendSocket: ' + JSON.stringify(obj)); + // Logger.info('sendSocket: ' + JSON.stringify(obj)); genericGrab(obj); }; var doGetBookmarkRedo = (obj) => { - // logger.info('sendSocket: ' + JSON.stringify(obj)); + // Logger.info('sendSocket: ' + JSON.stringify(obj)); genericGrab(obj); }; var doGetBookmarkRes = (url, res) => { logger.debug('doGetBookmarkRes'); - // logger.info('sendSocket: ' + JSON.stringify(obj)); + // Logger.info('sendSocket: ' + JSON.stringify(obj)); genericGrab(url, res); }; var doUpdateTagsDB = () => { logger.debug('Update the tags database...'); - dbCouch.view('getAllTags', 'getAllTags', function (err, body) { + dbCouch.view('getAllTags', 'getAllTags', function(err, body) { var masterList = []; if (!err) { - body.rows.forEach(function (doc) { + body.rows.forEach(function(doc) { masterList = masterList.concat(doc.value); }); @@ -169,24 +171,22 @@ var doUpdateTagsDB = () => { return self.indexOf(value) === index; }); - dbCouch.view('taglist', 'taglist', function (err, body) { - // logger.debug(body); + dbCouch.view('taglist', 'taglist', function(err, body) { + // Logger.debug(body); if (!err) { var outJSON = {}; - body.rows.forEach(function (doc) { + body.rows.forEach(function(doc) { doSaveTagsDB(doc.value, masterList); }); - } - else { + } else { logger.error('NO TAG LIST EXISTS'); } }); - } - else { + } else { } }); @@ -200,7 +200,7 @@ var doSaveTagsDB = (orig, newList) => { _obj.taglist = newList; - dbCouch.insert(_obj, function (err, body, header) { + dbCouch.insert(_obj, function(err, body, header) { if (err) { logger.error('Error updating into couch'); return; @@ -221,8 +221,7 @@ busEmitter.on('getBookmarkRedo', doGetBookmarkRedo); busEmitter.on('updateTagsDB', doUpdateTagsDB); busEmitter.on('saveTagsDB', doSaveTagsDB); -function doEngadget(body, url) -{ +function doEngadget(body, url) { logger.info('GRABBING Engadget'); var obj = {}, tdihbody, i, urlObj, urlPrefix; @@ -239,8 +238,8 @@ function doEngadget(body, url) urlPrefix = urlObj.protocol + '//' + urlObj.host + '/'; try { - tdihbody.find('IMG').each(function (i, elem) { - let s, src = $(this).attr("src"); + tdihbody.find('IMG').each(function(i, elem) { + let s, src = $(this).attr('src'); if (src !== null) { if (!STRING(src).startsWith('http')) { @@ -254,7 +253,7 @@ function doEngadget(body, url) s = 'http://image.silvrtree.co.uk/900,fit/' + src; - $(this).attr("src", s); + $(this).attr('src', s); } }); @@ -274,8 +273,7 @@ function doEngadget(body, url) } -function doAndroidDeveloper(body, url) -{ +function doAndroidDeveloper(body, url) { logger.info('GRABBING AndroidDeveloper'); var obj = {}, tdihbody, i, urlObj, urlPrefix; @@ -292,8 +290,8 @@ function doAndroidDeveloper(body, url) urlPrefix = urlObj.protocol + '//' + urlObj.host + '/'; try { - tdihbody.find('IMG').each(function (i, elem) { - let s, src = $(this).attr("src"); + tdihbody.find('IMG').each(function(i, elem) { + let s, src = $(this).attr('src'); if (src !== null) { if (!STRING(src).startsWith('http')) { @@ -307,7 +305,7 @@ function doAndroidDeveloper(body, url) s = 'http://image.silvrtree.co.uk/900,fit/' + src; - $(this).attr("src", s); + $(this).attr('src', s); } }); @@ -327,9 +325,8 @@ function doAndroidDeveloper(body, url) } -function doReddit(body, url) -{ -logger.info('GRABBING REDDIT'); +function doReddit(body, url) { + logger.info('GRABBING REDDIT'); var obj = {}, tdihbody, i, urlObj, urlPrefix; var $ = cheerio.load(body); @@ -337,13 +334,13 @@ logger.info('GRABBING REDDIT'); tdihbody = $('DIV.entry'); - tdihbody.find('A.thumbnail').each(function (i, elem) { + tdihbody.find('A.thumbnail').each(function(i, elem) { logger.warn($(this)); }); logger.info('++++++'); - // logger.debug(tdihbody.html()); + // Logger.debug(tdihbody.html()); logger.debug(tdihbody.length); tdihbody = cleaner(tdihbody); @@ -381,15 +378,14 @@ function genericProcessor(body, url) { tdihbody = cleaner(tdihbody); logger.debug(title); - } - else { + } else { logger.warn('Using whole body'); - // bah. nothing to reduce so just grab the body, tidy it and use that + // Bah. nothing to reduce so just grab the body, tidy it and use that tdihbody = $('BODY'); if (tdihbody.length === 0) { - tdihbody = $(":root"); + tdihbody = $(':root'); } @@ -398,14 +394,14 @@ function genericProcessor(body, url) { logger.debug(title); } - // logger.info(util.inspect(tdihbody)); + // Logger.info(util.inspect(tdihbody)); urlObj = URL.parse(url); urlPrefix = urlObj.protocol + '//' + urlObj.host + '/'; try { - tdihbody.find('IMG').each(function (i, elem) { - let s, src = $(this).attr("src"); + tdihbody.find('IMG').each(function(i, elem) { + let s, src = $(this).attr('src'); console.log('!!!!' + src); if (src !== null && typeof src !== 'undefined') { @@ -420,7 +416,7 @@ function genericProcessor(body, url) { s = 'http://image.silvrtree.co.uk/900,fit/' + src; - $(this).attr("src", s); + $(this).attr('src', s); } }); @@ -446,40 +442,38 @@ function processBody(body, url, _id, _rev) { - // try to find a body to grab + // Try to find a body to grab urlObj = URL.parse(url); logger.debug('host:', urlObj.host); var flag; - for (i=0;i
- <%= data[i].entry.tags %> + <% if (typeof data[i].entry.tags !== 'undefined') { %> + TAGS: + <%=data[i].entry.tags.solid %> + + <% } %> +