Created
February 8, 2017 00:39
-
-
Save lodi-g/0bd0c221fa8dbf36cd69c506fd1b77ac to your computer and use it in GitHub Desktop.
Just a twitch username checker in nodejs.
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
#!/usr/bin/env node | |
const ArgumentParser = require("argparse").ArgumentParser; | |
const fs = require("fs"); | |
const colors = require("colors"); | |
const request = require("request"); | |
const parser = new ArgumentParser({ | |
version: "0.0.1", | |
addHelp: true, | |
description: "Print if a username in <file> is not registered on twitch.tv" | |
}); | |
parser.addArgument("file", { help: "File which contains a list of usernames" }); | |
parser.addArgument("--verbose", { help: "Enables verbose mode", | |
required: false, | |
defaultValue: false }); | |
const args = parser.parseArgs(); | |
if (!fs.existsSync(args.file)) { | |
console.error(`${"Error".red}: file '${args.file}' does not exists.`.bold); | |
process.exit(1); | |
} | |
const users = fs.readFileSync(args.file).toString().replace(/\r/g, "") | |
.split("\n"); | |
if (args.verbose) | |
console.log(`Successfully loaded ${users.length} users: ${users.join(", ")}.`); | |
const clientId = "Your twitch client id key"; | |
const opts = { | |
"url": "", | |
headers: { | |
"Accept": "application/vnd.twitchtv.v5+json", | |
"Client-ID": clientId | |
} | |
}; | |
for (let user of users) { | |
opts.url = `https://api.twitch.tv/kraken/users?login=${user}`; | |
request(opts, (err, res, body) => { | |
body = JSON.parse(body); | |
if (body["_total"] == 0) | |
console.log(`Username ${colors.green(user).bold} is available.`); | |
else if (args.verbose) | |
console.log(`Username ${colors.red(user).bold} is unavailable.`); | |
}); | |
} |
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
{ | |
"name": "twitch-checker", | |
"version": "0.0.1", | |
"description": "A simple twitch account checker.", | |
"main": "checker.js", | |
"scripts": { | |
"test": "node checker.js" | |
}, | |
"author": "lodi-g", | |
"license": "MIT", | |
"dependencies": { | |
"argparse": "^1.0.9", | |
"colors": "^1.1.2", | |
"request": "^2.79.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment