Skip to content

Instantly share code, notes, and snippets.

@kharandziuk
Last active April 27, 2017 10:59
Show Gist options
  • Select an option

  • Save kharandziuk/70ce172c89dd9c1322375edbe80db988 to your computer and use it in GitHub Desktop.

Select an option

Save kharandziuk/70ce172c89dd9c1322375edbe80db988 to your computer and use it in GitHub Desktop.
checks instagram for absent usernames which absent for some reasons: some them should be available.
const log = require('debug')('app')
const request = require('superagent')
const Promise = require('bluebird')
const H = require('highland')
const { permutations } = require('permutations-stream')
const _ = require('lodash')
const retry = require('bluebird-retry')
symbols = 'abcdefghijklmnopqrstuvwxyz0123456789_.'
function instaCall(name) {
const startMark= process.hrtime()
const call = request
.get(`https://www.instagram.com/${name}/`)
return Promise.resolve(call)
.then(() => null)
.catch({status: '404'}, function(e) {
return name
})
.then(name => {
const [elapsedS, elapsedNS] = process.hrtime(startMark)
return [name, elapsedS * Math.pow(10, 9) + elapsedNS]
})
.catch(function(e) {
console.log(e.message)
console.log(e)
throw e
})
}
permutations(1000, symbols)
.map(x => x.join(''))
.reject(x =>
_.startsWith(x, '.') ||
_.endsWith(x, '.') ||
!_.isNaN(Number(x))
)
.map(name =>
H(retry(instaCall, {args: [name]}))
)
.parallel(3)
.reject(([name]) => _.isNull(name))
.map(x => x.join(' ') + '\n')
.pipe(process.stdout)
{
"dependencies": {
"bluebird": "^3.5.0",
"bluebird-retry": "^0.10.1",
"chai": "^3.5.0",
"debug": "^2.6.4",
"highland": "^2.10.5",
"lodash": "^4.17.4",
"mocha": "^3.2.0",
"permutations-stream": "git@github.com:kharandziuk/permutations-stream.git#master",
"superagent": "^3.5.2"
},
"scripts": {
"test": "mocha"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment