Comparing version 1.1.0 to 1.1.1
@@ -5,2 +5,4 @@ var request = require('request') | ||
var colors = require('colors') | ||
const util = require('util') | ||
const exec = require('child_process').exec | ||
@@ -11,4 +13,37 @@ // NOTE: | ||
function logIt(message, disableConsole) { | ||
if (!disableConsole) { | ||
console.log(message) | ||
} | ||
} | ||
function saveToFile(output, results) { | ||
if (output !== undefined) { | ||
fs.writeFile(output, JSON.stringify(results, null, 2), 'utf8', (err) => { | ||
if (err) { | ||
console.err('Error writing to file ' + output + ': ' + err) | ||
} | ||
}) | ||
} | ||
} | ||
function errorTryingToOpen(error, stdout, stderr) { | ||
if (error) { | ||
console.log(`Error trying to open link in browser: ${error}`) | ||
console.log(`stdout: ${stdout}`) | ||
console.log(`stderr: ${stderr}`) | ||
} | ||
} | ||
function openInBrowser(open, results) { | ||
if (open !== undefined) { | ||
// open is the first X number of links to open | ||
results.slice(0, open).forEach((result, i) => { | ||
exec(`open ${result.link}`, errorTryingToOpen); | ||
}) | ||
} | ||
} | ||
function googleIt(config) { | ||
var {query, numResults, userAgent, output, options = {}} = config | ||
var {query, numResults, userAgent, output, open, options = {}} = config | ||
var defaultOptions = { | ||
@@ -26,10 +61,5 @@ url: `https://www.google.com/search?q=${query}&gws_rd=ssl&num=${numResults || 10}`, | ||
} else { | ||
var results = getResults(body, config['no-display']) | ||
if (output !== undefined) { | ||
fs.writeFile(output, JSON.stringify(results, null, 2), 'utf8', (err) => { | ||
if (err) { | ||
console.err('Error writing to file ' + output + ': ' + err) | ||
} | ||
}) | ||
} | ||
var results = getResults(body, config['no-display'], config['disableConsole']) | ||
saveToFile(output, results) | ||
openInBrowser(open, results) | ||
return resolve(results); | ||
@@ -51,12 +81,12 @@ } | ||
function display(results) { | ||
function display(results, disableConsole) { | ||
results.forEach((result, i) => { | ||
console.log(result.title.blue) | ||
console.log(result.link.green) | ||
console.log(result.snippet) | ||
console.log("\n") | ||
logIt(result.title.blue, disableConsole) | ||
logIt(result.link.green, disableConsole) | ||
logIt(result.snippet, disableConsole) | ||
logIt("\n", disableConsole) | ||
}) | ||
} | ||
function getResults(data, noDisplay) { | ||
function getResults(data, noDisplay, disableConsole) { | ||
const $ = cheerio.load(data) | ||
@@ -87,3 +117,3 @@ var results = [] | ||
if (!noDisplay) { | ||
display(results) | ||
display(results, disableConsole) | ||
} | ||
@@ -90,0 +120,0 @@ return results |
@@ -31,5 +31,9 @@ const optionDefinitions = [ | ||
// option to limit results to only these two sites | ||
{ name: 'stackoverflow-github-only', alias: 'X', type: Boolean } | ||
{ name: 'stackoverflow-github-only', alias: 'X', type: Boolean }, | ||
// option to open the first X number of results directly in browser | ||
// (only tested on Mac!). | ||
{ name: 'open', alias: 'O', type: Number } | ||
] | ||
module.exports = optionDefinitions |
{ | ||
"name": "google-it", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A CLI and Node.js library to help retrieve, display, and store Google search results", | ||
@@ -24,10 +24,11 @@ "main": "./googleIt.js", | ||
"command-line-args": "^5.0.0", | ||
"ora": "^1.3.0", | ||
"ora": "^2.0.0", | ||
"request": "^2.81.0" | ||
}, | ||
"devDependencies": { | ||
"codecov": "^3.0.0", | ||
"eslint": "^4.8.0", | ||
"mocha": "^5.0.0", | ||
"prettier": "1.10.2" | ||
"prettier": "1.11.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# google-it [![Build Status](https://travis-ci.org/PatNeedham/google-it.svg?branch=master)](https://travis-ci.org/PatNeedham/google-it) [![Greenkeeper badge](https://badges.greenkeeper.io/PatNeedham/google-it.svg)](https://greenkeeper.io/) | ||
# google-it [![Build Status](https://travis-ci.org/PatNeedham/google-it.svg?branch=master)](https://travis-ci.org/PatNeedham/google-it) [![Greenkeeper badge](https://badges.greenkeeper.io/PatNeedham/google-it.svg)](https://greenkeeper.io/) [![npm version](https://badge.fury.io/js/google-it.svg)](https://badge.fury.io/js/google-it) | ||
@@ -21,4 +21,6 @@ A simple library to convert Google search results to JSON output, with an interactive display option coming in the near future. | ||
## Upcoming Features Roadmap | ||
`$ google-it --query="open whisper systems" -O 5` | ||
![GIF of opening-in-browser](open-results-in-browser.gif?raw=true "google-it-to-browser") | ||
### Command Line Arguments | ||
@@ -34,2 +36,4 @@ - [x] *query* - the query that should be sent to the Google search | ||
- [ ] *stackoverflow-github-only* - option to limit results to only these two sites | ||
- [x] *open* - opens the first X number of results in the browser after finishing query | ||
- [x] *disableConsole* - intended to be used with programmatic use, so that the color-coded search results are not displayed in the terminal (via console.log) when not wanted. | ||
@@ -36,0 +40,0 @@ ### Programmatic Use in NodeJS environment |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
7670873
25
665
61
4
2
+ Addedansi-regex@3.0.1(transitive)
+ Addedclone@1.0.4(transitive)
+ Addeddefaults@1.0.4(transitive)
+ Addedora@2.1.0(transitive)
+ Addedstrip-ansi@4.0.0(transitive)
+ Addedwcwidth@1.0.1(transitive)
- Removedora@1.4.0(transitive)
Updatedora@^2.0.0