<commit_before>'use strict'
// var SDS011Wrapper = require("sds011-wrapper")
var sensor = null
var stringify = require('fast-safe-stringify')
var icloud = require('find-my-iphone').findmyphone
var consoleLogger = require('../../util/logger.js')

function AppleDeviceTracker (config, eventEmitter) {
  this.config = config
  this.eventEmitter = eventEmitter
  icloud.apple_id = process.env.APPLE_ID || this.config.appleId
  icloud.password = process.env.APPLE_PW || this.config.applePassword
}

AppleDeviceTracker.prototype.getLocation = function () {
  var eventEmitter = this.eventEmitter
  var config = this.config
  icloud.getDevices(function (error, devices) {
    if (error) {
      return error
    }
    devices.forEach(function (d) {
      if (config.ignoreDeviceName) {
        var idn = new RegExp(config.ignoreDeviceName)
        if (idn.test(d.name) || idn.test(d.deviceDisplayName)) {
          if (config.debug) {
            consoleLogger.log('ignoring device ' + config.ignoreDeviceName + ': ' + d.name + ' ' + d.deviceDisplayName)
          }
          return null
        }
      }
      if (config.filterDeviceName) {
        var fdn = new RegExp(config.filterDeviceName)
        if (!(fdn.test(d.name) || fdn.test(d.deviceDisplayName))) {
          if (config.debug) {
            consoleLogger.log('filter did not match' + config.filterDeviceName + ': ' + d.name + ' ' + d.deviceDisplayName)
          }
          return null
        }
      }
      var device = null
      if (d.location /* && d.lostModeCapable */) {
        device = d
      } else {
        device = null
        return
      }
      if (d.location) {
        icloud.getLocationOfDevice(device, function (err, location) {
          if (err) {
            return consoleLogger.error(err)
          }
          device.geoip = {
            location: [device.location.longitude, device.location.latitude]
          }
          device.message = device.name +
            ' (' + device.modelDisplayName + '): ' + location
          if (location) {
            device.location.address = location
          } else {
            device.message = device.name +
            ' (' + device.modelDisplayName + '): ' + device.location.latitude + ',' + device.location.longitude +
            ', https://www.google.de/maps/search/maps+' + device.location.latitude + ',' + device.location.longitude
          }
          eventEmitter.emit('location', {geoip: device.geoip, address: location}, {sourceName: 'icloud'})
          eventEmitter.emit('data.raw', stringify(device), {sourceName: 'icloud'})
          if (config.debug) {
            consoleLogger.debug(stringify(device))
          }
        })
      } else {
        // consoleLogger.log(d.displayName)
      }
    })
  })
}
<commit_msg>emit location event, which could be used by other plugins to get GPS pos.<commit_after>'use strict'
// var SDS011Wrapper = require("sds011-wrapper")
var sensor = null
var stringify = require('fast-safe-stringify')
var icloud = require('find-my-iphone').findmyphone
var consoleLogger = require('../../util/logger.js')

function AppleDeviceTracker (config, eventEmitter) {
  this.config = config
  this.eventEmitter = eventEmitter
  icloud.apple_id = process.env.APPLE_ID || this.config.appleId
  icloud.password = process.env.APPLE_PW || this.config.applePassword
}

AppleDeviceTracker.prototype.getLocation = function () {
  var eventEmitter = this.eventEmitter
  var config = this.config
  icloud.getDevices(function (error, devices) {
    if (error) {
      return error
    }
    devices.forEach(function (d) {
      if (config.ignoreDeviceName) {
        var idn = new RegExp(config.ignoreDeviceName)
        if (idn.test(d.name) || idn.test(d.deviceDisplayName)) {
          if (config.debug) {
            consoleLogger.log('ignoring device ' + config.ignoreDeviceName + ': ' + d.name + ' ' + d.deviceDisplayName)
          }
          return null
        }
      }
      if (config.filterDeviceName) {
        var fdn = new RegExp(config.filterDeviceName)
        if (!(fdn.test(d.name) || fdn.test(d.deviceDisplayName))) {
          if (config.debug) {
            consoleLogger.log('filter did not match' + config.filterDeviceName + ': ' + d.name + ' ' + d.deviceDisplayName)
          }
          return null
        }
      }
      var device = null
      if (d.location /* && d.lostModeCapable */) {
        device = d
      } else {
        device = null
        return
      }
      if (d.location) {
        icloud.getLocationOfDevice(device, function (err, location) {
          if (err) {
            return consoleLogger.error(err)
          }
          device.geoip = {
            location: [device.location.longitude, device.location.latitude]
          }
          device.message = device.name +
            ' (' + device.modelDisplayName + '): ' + location
          if (location) {
            device.location.address = location
          } else {
            device.message = device.name +
            ' (' + device.modelDisplayName + '): ' + device.location.latitude + ',' + device.location.longitude +
            ', https://www.google.de/maps/search/maps+' + device.location.latitude + ',' + device.location.longitude
          }
          eventEmitter.emit('location', {geoip: device.geoip, address: location}, {sourceName: 'icloud'})
          if (!config.emitOnlyLocationEvent) {
            eventEmitter.emit('data.raw', stringify(device), {sourceName: 'icloud'})
          }
          if (config.debug) {
            consoleLogger.debug(stringify(device))
          }
        })
      } else {
        // consoleLogger.log(d.displayName)
      }
    })
  })
}

{'fraction_non_alphanumeric': 0.1299205648720212, 'fraction_numerical': 0.002118270079435128, 'mean_word_length': 2.1975169300225734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2635423', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1669, 'n_words': 305}