<commit_before>/* global _ */

/* jshint ignore:start */
import util.underscore as _;
import util.ajax as ajax;
/* jshint ignore:end */

exports = (function (cb) {
  "use strict";

  // When we have multiple services this can be a array to iterate through
  var service_url = 'http://ip-api.com/json';

  ajax.get({
    url: service_url
  }, function (err, res) {
    if (res && _.has(res, "countryCode")) {
      cb(res.countryCode);
    } else {
      cb('UNKNOWN');
    }
  });
});<commit_msg>added fallback to country code finder<commit_after>/* global _ */

/* jshint ignore:start */
import util.underscore as _;
import util.ajax as ajax;
/* jshint ignore:end */

exports = (function (cb) {
  "use strict";

  // When we have multiple services this can be a array to iterate through
  var service_url = [
                    ['country_code', 'http://freegeoip.net/json/'],
                    ['countryCode', 'http://ip-api.com/ejson']
                    ],
    it = 0,
    ajax_req = function () {
      ajax.get({
        url: service_url[it][1]
      }, function (err, res) {
        if (res && _.has(res, service_url[it][0])) {
          cb(res[service_url[it][0]]);
        } else {
          ++it;
          ajax_req();
        }
      });
    };

  ajax_req();
});
{'fraction_non_alphanumeric': 0.15974941268598278, 'fraction_numerical': 0.0031323414252153485, 'mean_word_length': 2.1791044776119404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '2431815', 'n_tokens_mistral': 431, 'n_tokens_neox': 411, 'n_words': 108}