<commit_before>var mongoose = require('mongoose')
var request = require('request')
var eventsSchema = new mongoose.Schema({
  // Follows fullcalendar's event object model, display options omitted:
  // http://fullcalendar.io/docs/event_data/Event_Object/
  id: String, // this is the slug
  title: String, // Display title
  start: String, // Moment-ish date, ISO8601 string, http://en.wikipedia.org/wiki/ISO_8601
  end: String, // same ^^
  allDay: Boolean, // shows time of day or not
  url: String, // an external link you can use to override where to go when clicking

  // These options are used within brigadehub for content storage
  description: String,
  location: String,
  hosts: Array
})

eventsSchema.methods.fetchGoogleEvents = function (cb) {
  cb(null, {})
}

eventsSchema.statics.fetchMeetupEvents = function (meetupid) {
  var Events = this
  return new Promise(function (resolve, reject) {
    getEvents(meetupid, function (err, aggregate) {
      if (err) console.error(err)
      if (aggregate.length < 1) {
        reject('We were unable to find any events attached to your Meetup account. Please check your Meetup.com credentials if you were expecting to import some events. ')
      } else {
        aggregate.forEach(function (outing) {
          Events.find({'id': outing.id}, function (err, foundEvents) {
            if (foundEvents.length < 1) {
              if (err) console.error(err)
              var eventData = createUpdateEventData(outing, {})
              var newEvent = new Events(eventData)
              newEvent.save(function (err) {
                if (err) console.error(err)
              })
            } else {
              var thisEvent = foundEvents[0]
              thisEvent = createUpdateEventData(outing, thisEvent)
              thisEvent.save(function (err) {
                if (err) console.error(err)
              })
            }
          })
        })
        resolve()
      }
    })
  })
}

function getEvents (meetupid, callback) {
  request(meetupid, function (error, response, body) {
    if (!error && response.statusCode === 200) {
      var parsed = JSON.parse(body)
      return callback(null, parsed.results)
    } else {
      return callback(error, [])
    }
  })
}

function createUpdateEventData (event, original, brigade) {
  var eventData = original || {}
  eventData.id = event.id || ''
  eventData.title = event.name || ''
  eventData.url = event.event_url || ''
  eventData.description = event.description || ''
  eventData.location = event.venue.address_1 + ' ' + event.venue.city || ''
  eventData.hosts = event.venue.name || ''
  eventData.start = new Date(event.time).toISOString() || ''
  eventData.end = new Date(event.time + event.duration).toISOString() || ''
  return eventData
}

module.exports = mongoose.model('Events', eventsSchema)<commit_msg>disable event updating when fetching events from meetup.<commit_after>var mongoose = require('mongoose')
var request = require('request')
var eventsSchema = new mongoose.Schema({
  // Follows fullcalendar's event object model, display options omitted:
  // http://fullcalendar.io/docs/event_data/Event_Object/
  id: String, // this is the slug
  title: String, // Display title
  start: String, // Moment-ish date, ISO8601 string, http://en.wikipedia.org/wiki/ISO_8601
  end: String, // same ^^
  allDay: Boolean, // shows time of day or not
  url: String, // an external link you can use to override where to go when clicking

  // These options are used within brigadehub for content storage
  description: String,
  location: String,
  hosts: Array
})

eventsSchema.methods.fetchGoogleEvents = function (cb) {
  cb(null, {})
}

eventsSchema.statics.fetchMeetupEvents = function (meetupid) {
  var Events = this
  return new Promise(function (resolve, reject) {
    getEvents(meetupid, function (err, aggregate) {
      if (err) console.error(err)
      if (aggregate.length < 1) {
        reject('We were unable to find any events attached to your Meetup account. Please check your Meetup.com credentials if you were expecting to import some events. ')
      } else {
        aggregate.forEach(function (outing) {
          Events.find({'id': outing.id}, function (err, foundEvents) {
            if (foundEvents.length < 1) {
              if (err) console.error(err)
              var eventData = createUpdateEventData(outing)
              var newEvent = new Events(eventData)
              newEvent.save(function (err) {
                if (err) console.error(err)
              })
            }
            // else {
            //   var thisEvent = foundEvents[0]
            //   thisEvent = createUpdateEventData(outing)
            //   thisEvent.save(function (err) {
            //     if (err) console.error(err)
            //   })
            // }
          })
        })
        resolve()
      }
    })
  })
}

function getEvents (meetupid, callback) {
  request(meetupid, function (error, response, body) {
    if (!error && response.statusCode === 200) {
      var parsed = JSON.parse(body)
      return callback(null, parsed.results)
    } else {
      return callback(error, [])
    }
  })
}

function createUpdateEventData (event) {
  var eventData = {}
  eventData.id = event.id || ''
  eventData.title = event.name || ''
  eventData.url = event.event_url || ''
  eventData.description = event.description || ''
  eventData.location = event.venue.address_1 + ' ' + event.venue.city || ''
  eventData.hosts = event.venue.name || ''
  eventData.start = new Date(event.time).toISOString() || ''
  eventData.end = new Date(event.time + event.duration).toISOString() || ''
  return eventData
}

module.exports = mongoose.model('Events', eventsSchema)
{'fraction_non_alphanumeric': 0.12171628721541156, 'fraction_numerical': 0.005253940455341506, 'mean_word_length': 2.642219387755102, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7510060', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1625, 'n_words': 444}