Created
August 28, 2017 10:32
-
-
Save Dafrok/48b301239dd8c91773989b55508b7b40 to your computer and use it in GitHub Desktop.
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 http = require('http') | |
const fs = require('fs') | |
const path = require('path') | |
const STEP = 50 | |
const MAX = 65536 | |
const file = {} | |
const getKana = range => new Promise((resolve, reject) => { | |
let text = '' | |
for (let i = range.min; i < range.max; i++) { | |
try { | |
text += encodeURIComponent(String.fromCharCode(i)) | |
} | |
catch (e) {} | |
} | |
if (!text) { | |
resolve({}) | |
} | |
http.get(`http://app.tgbus.com/kanji/ToJp.ashx?keyword=${text}&encode=utf-8&app=3ds`, response => { | |
let body = '' | |
response.on('data', function(d) { | |
body += d | |
}) | |
response.on('end', function() { | |
resolve(new Function(`return ${body}`)()) | |
}) | |
}) | |
}) | |
async function getData() { | |
let i = 0 | |
while (i < 65536) { | |
console.log(`Fetching ${i} to ${i + STEP}...`) | |
await getKana({max: i + STEP, min: i}).then(data => { | |
Object.assign(file, data) | |
}) | |
i += STEP | |
} | |
console.log('Writing data...') | |
fs.writeFileSync(path.resolve(__dirname, 'result.json'), JSON.stringify(file)) | |
console.log('Done. Please check `./result.json`.') | |
} | |
getData() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment