-
-
Save YodaLightsabr/00799a736d560a5d954420b3f7a797d3 to your computer and use it in GitHub Desktop.
Zoogle CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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