Last active
March 28, 2017 12:04
-
-
Save davidsharp/379226d665bc8f17b589d2c1335a1dd0 to your computer and use it in GitHub Desktop.
Quickly thrown together CLI tool for Jisho requests
This file contains hidden or 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
| const cmdr = require('commander'), | |
| request = require('request') | |
| cmdr | |
| .option('-t, --text [value]') | |
| .option('-c, --common') | |
| .parse(process.argv); | |
| const Jisho = 'http://jisho.org/api/v1/search/words?keyword=' | |
| request(Jisho+encodeURIComponent(cmdr.text), function (error, response, html) { | |
| if (!error && response.statusCode == 200) { | |
| let data = (JSON.parse(response.body).data) | |
| data.forEach(c=>{if(!cmdr.common||c.is_common){ | |
| console.log( c.japanese.map(_c=>([_c.word,_c.reading].filter(f=>!!f).join(' – '))).join(', ') ) | |
| console.log( ` • ${c.senses.map(_c=>_c.parts_of_speech).join(', ')}${!c.is_common?' (uncommon)':''}` ) | |
| console.log( ` • Meaning: ${c.senses.map(_c=>(_c.english_definitions).map(_c=>('"'+_c+'"')).join(', '))}` ) | |
| console.log( '~~~~~~~~~~~~~~~' ) | |
| }}) | |
| } | |
| }) | |
| //Used like: `node jisho -t "watashi" -c` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment