UNPKG

iloa

Version:

A command line tool for gaining knowledge.

1 lines 3.05 kB
'use strict';var themes=require('../../themes');var tools=require('../../tools');var noon=require('noon');exports.Article=function(body,tofile){var tf=tofile;var CFILE=process.env.HOME+'/.iloa.noon';tools.checkConfig(CFILE);var config=noon.load(CFILE);var theme=themes.loadTheme(config.theme);themes.label(theme,'right','Title',body.Heading);themes.label(theme,'right','Entity',body.Entity);themes.label(theme,'right','Source',body.AbstractSource);themes.label(theme,'right','URL',body.AbstractURL);themes.label(theme,'right','Text',tools.wrapStr(body.AbstractText,true,true));if(body.Results.length>0){themes.label(theme,'down','Primary Results');for(var i=0;i<=body.Results-1;i++){var res=body.Results[i];console.log(res.Text+'\n'+res.FirstURL);tofile[['resultText'+i]]=res.Text;tofile[['resultUrl'+i]]=res.FirstURL;}}tofile.title=body.Heading;tofile.entity=body.Entity;tofile.abstractSource=body.AbstractSource;tofile.abstractUrl=body.AbstractURL;tofile.text=body.AbstractText;return tf;};exports.Abstract=function(body,tofile){var tf=tofile;var CFILE=process.env.HOME+'/.iloa.noon';tools.checkConfig(CFILE);var config=noon.load(CFILE);var theme=themes.loadTheme(config.theme);themes.label(theme,'right','Title',body.Heading);themes.label(theme,'right','Source',body.AbstractSource);themes.label(theme,'right','URL',body.AbstractURL);tofile.title=body.Heading;tofile.abstractSource=body.AbstractSource;tofile.abstractUrl=body.AbstractURL;return tf;};exports.Image=function(body,tofile){var tf=tofile;var CFILE=process.env.HOME+'/.iloa.noon';tools.checkConfig(CFILE);var config=noon.load(CFILE);var theme=themes.loadTheme(config.theme);themes.label(theme,'right','Image URL',body.Image);tofile.image=body.Image;return tf;};exports.Raw=function(body,tofile){var tf=tofile;var CFILE=process.env.HOME+'/.iloa.noon';tools.checkConfig(CFILE);var config=noon.load(CFILE);var theme=themes.loadTheme(config.theme);themes.label(theme,'right','Answer Type',body.AnswerType);console.log(body.Answer);return tf;};exports.RelatedTopics=function(body,tofile){var tf=tofile;var CFILE=process.env.HOME+'/.iloa.noon';tools.checkConfig(CFILE);var config=noon.load(CFILE);var theme=themes.loadTheme(config.theme);var rtArray=body.RelatedTopics;var rcont=[];var tcont=[];for(var i=0;i<=rtArray.length-1;i++){var hash=rtArray[i];if(hash.Result!==undefined){rcont.push(hash);}else if(hash.Name!==undefined){tcont.push(hash);}}if(rcont!==[]){themes.label(theme,'down','Related');for(var _i=0;_i<=rcont.length-1;_i++){var rhash=rcont[_i];console.log(tools.wrapStr(rhash.Text,true,true)+'\n'+rhash.FirstURL);tofile[['relatedText'+_i]]=rhash.Text;tofile[['relatedUrl'+_i]]=rhash.FirstURL;}}if(tcont!==[]){for(var _i2=0;_i2<=tcont.length-1;_i2++){var thash=tcont[_i2];themes.label(theme,'right','Topics',thash.Name);tofile[['topicName'+_i2]]=thash.Name;var tArray=thash.Topics;for(var j=0;j<=tArray.length-1;j++){var tResult=tArray[j];console.log(tResult.Text+'\n'+tResult.FirstURL);tofile[['topicText'+_i2]]=tResult.Text;tofile[['topicUrl'+_i2]]=tResult.FirstURL;}}}return tf;};