<commit_before>'use strict';
//var mongoose = require('mongoose'),
//  Schema = mongoose.Schema,
//  request = require('request');

var request = require('request');
var databaseUrl = "ballstrikers"; // "username:<EMAIL>/mydb"
var collections = ["tournaments"];
var db = require("mongojs").connect(databaseUrl, collections);


/**
 * Tournament Schema
 */
//var TournamentSchema = new Schema({
//  modified: { type: Date, default: Date.now },
//  event: {},
//  courseInfos: [],
//  field: []
//});
//
///**
// * Register Model
// */
//mongoose.model('Tournament', TournamentSchema);
//var Tournament = mongoose.model('Tournament');

/**
 * Get and Save tournament.js
 */


var tournamentSetup = function() {

  request({uri: 'http://www.pgatour.com/data/r/current/setup.json', json: true},
    function(error, response, body) {
      if(error){ console.log('error1') }

      console.log('setup record retrieved');

      //check for tournament object
      if(typeof body.trn === "undefined"){
        console.log('tournament setup record retrieved but undefined');
      }

      var setupObj = {
        event: body.trn.event,
        courses: body.trn.courseInfos,
        field: body.trn.field,
        rounds: body.trn.rnds
      };

      db.tournaments.save(setupObj,
        function(error, saved){
          if(error || !saved){console.log('setup file not saved: ' + error);}

          console.log('setup record saved');
        });


      //save
//      var setupFile = new Tournament(body.trn);
//      setupFile.save(function(err){
//        if(err){console.log('error2');}
//
//        console.log('setup record saved');
//      })<commit_msg>update setupTournament file to support heroku and local dev<commit_after>'use strict';
var request = require('request');
var databaseUrl = process.env.MONGOHQ_URL || "ballstrikers"; // heroku MongoHQ || local default
var collections = ["tournaments"];
var db = require("mongojs").connect(databaseUrl, collections);

/**
 * Get and Save tournament.js
 */
var tournamentSetup = function() {

  request({uri: 'http://www.pgatour.com/data/r/current/setup.json', json: true},
    function(error, response, body) {
      if(error){
        console.log(error);
        return;
      }

      console.log('setup record retrieved');

      //check for tournament object
      if(typeof body.trn === "undefined"){
        console.log('tournament setup record retrieved but undefined');
        return;
      }

      var setupObj = {
        event: body.trn.event,
        courses: body.trn.courseInfos,
        field: body.trn.field,
        rounds: body.trn.rnds
      };

      db.tournaments.save(setupObj,
        function(error, saved){
          if(error || !saved){
            console.log('setup file not saved: ' + error);
            return;
          }

          console.log('setup record saved: ' + saved);
        });

{'fraction_non_alphanumeric': 0.15955601803676725, 'fraction_numerical': 0.000693721817551162, 'mean_word_length': 2.6368221941992434, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2811625', 'n_tokens_mistral': 880, 'n_tokens_neox': 845, 'n_words': 195}