Skip to content

Instantly share code, notes, and snippets.

@YodaLightsabr
Created October 15, 2021 05:52
Show Gist options
  • Save YodaLightsabr/00799a736d560a5d954420b3f7a797d3 to your computer and use it in GitHub Desktop.
Save YodaLightsabr/00799a736d560a5d954420b3f7a797d3 to your computer and use it in GitHub Desktop.
Zoogle CLI
// DON'T FORGET TO RUN "npm install node-fetch@2.6.1"
const fetch = require('node-fetch'); // use version 2.6.1
const readline = require("readline");
const Zoogle = `
\x1b[0m\x1b[34mZ\x1b[31mo\x1b[1;33mo\x1b[34mg\x1b[32ml\x1b[31me \x1b[0mCLI
`;
console.clear();
console.log(Zoogle);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on("close", function() {
console.clear();
console.log(Zoogle);
console.log('Closing Zoogle CLI...');
process.exit(0);
});
function search (question) {
rl.question(question, query => {
fetch('https://zoogle.zephyrnet.hackclub.com/jq/' + encodeURIComponent(query)).then(response => response.json()).then(json => {
console.clear();
console.log(Zoogle);
console.log(`\x1b[0mHere are the results for \x1b[2m${query}\x1b[0m\n`);
if (json.length) console.log(json.map(result => {
return `\x1b[0m\x1b[4m\x1b[34m${result.Title}\x1b[0m\n${result.Blurb}`;
}).join('\n\n'));
if (!json.length) console.log('\x1b[0m\x1b[31mNo results\x1b[0m');
console.log('\x1b[0m\nView this page on \x1b[0m\x1b[34mZ\x1b[31mo\x1b[1;33mo\x1b[34mg\x1b[32ml\x1b[31me\x1b[0m at \x1b[4m\x1b[34mhttps://zoogle.zephyrnet.hackclub.com/q/' + encodeURIComponent(query));
search("\x1b[0m\nEnter another search term \x1b[2m");
})
});
}
search("\x1b[0mEnter search term \x1b[2m");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment