Skip to content

Instantly share code, notes, and snippets.

@Dafrok
Created August 28, 2017 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dafrok/48b301239dd8c91773989b55508b7b40 to your computer and use it in GitHub Desktop.
Save Dafrok/48b301239dd8c91773989b55508b7b40 to your computer and use it in GitHub Desktop.
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