<commit_before>#!/usr/bin/env node
var cmd = process.argv[2];
var id = process.argv[3];
var filter = process.argv[4];

function usage() {
  console.log('usage: twi (tweet|user) (id|screen_name) [filter]');
}

if (!id) {
  usage();
  process.exit();
}

var commands = {
  tweet: 'statuses/show.json?id=',
  user: 'users/show.json?screen_name=',
};
var path = commands[cmd];
if (!path) {
  console.log('unknown command');
  usage();
  process.exit(1);
}

var request = require('request');
var env = process.env;

request.get({
  oauth: {
    consumer_key    : env.TWITTER_CONSUMER_KEY,
    consumer_secret : env.TWITTER_CONSUMER_SECRET,
    token           : env.TWITTER_TOKEN,
    token_secret    : env.TWITTER_TOKEN_SECRET,
  },
  url: 'https://api.twitter.com/1.1/' + path + id,
  json: true,
}, function(err, res, data) {
    if (err) throw err;
    if (res.statusCode !== 200) {
      if (data.errors) {
        data.errors.forEach(function(error) {
          console.error(error.message);
        });
      } else {
        console.error('status code: ' + res.statusCode);
      }
      return;
    }

    if (filter) {
      var o = {};
      var f = filter.split(',');
      for (var i = 0, len = f.length; i < len; i++) {
        var key = f[i];
        var value = data[key];
        if (typeof value !== 'undefined') {
          o[key] = value;
        }
      }
      console.log(o);<commit_msg>add optional oauth pool via `.twirc`<commit_after>#!/usr/bin/env node
var cmd = process.argv[2];
var id = process.argv[3];
var filter = process.argv[4];

function usage() {
  console.log('usage: twi (tweet|user) (id|screen_name) [filter]');
}

if (!id) {
  usage();
  process.exit();
}

var commands = {
  tweet: 'statuses/show.json?id=',
  user: 'users/show.json?screen_name=',
};
var resource = commands[cmd];
if (!resource) {
  console.log('unknown command');
  usage();
  process.exit(1);
}

// See if there's a Twitter oauth pool file.
var fs = require('fs');
var path = require('path');
var env = process.env;
var twirc = path.resolve(env.HOME, '.twirc');
var oauth;

if (fs.existsSync(twirc)) {
  oauth = JSON.parse(fs.readFileSync(twirc, 'utf8'));
  oauth = oauth[~~(Math.random() * oauth.length)];
} else {
  oauth = {
    consumer_key    : env.TWITTER_CONSUMER_KEY,
    consumer_secret : env.TWITTER_CONSUMER_SECRET,
    token           : env.TWITTER_TOKEN,
    token_secret    : env.TWITTER_TOKEN_SECRET,
  };
}

var request = require('request');

request.get({
  oauth: oauth,
  url: 'https://api.twitter.com/1.1/' + resource + id,
  json: true,
}, function(err, res, data) {
    if (err) throw err;
    if (res.statusCode !== 200) {
      if (data && data.errors) {
        data.errors.forEach(function(error) {
          console.error(error.message);
        });
      } else {
        console.error('status code: ' + res.statusCode);
      }
      return;
    }

    if (filter) {
      var o = {};
      var f = filter.split(',');
      for (var i = 0, len = f.length; i < len; i++) {
        var key = f[i];
        var value = data[key];
        if (typeof value !== 'undefined') {
          o[key] = value;
        }
      }
      console.log(o);
{'fraction_non_alphanumeric': 0.17381703470031545, 'fraction_numerical': 0.006624605678233439, 'mean_word_length': 2.6157354618015964, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3892274', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1145, 'n_words': 250}