<commit_before>require('dotenv').config({path: '../.env', silent: true});

import {EventEmitter} from 'events';

import objectAssign from 'object-assign';
import hashRegex from 'hash-regex';
import isRegexp from 'is-regexp';
import getPort from 'get-port';
import report from './report';

export default class Birdwatch {
	/**
	 * Initialize a new Birdwatch
	 *
	 * @param {Object} options
	 * @api public
	 */
	constructor(options) {
		const defaults = {
			logReports: true,
			server: true,
			port: 8417,
			testData: false,
			refreshTime: 600,
			url: '/birdwatch/tweets',
			cacheDir: `${__dirname}/cache`,
			sortBy: tweet => {
				return new Date(tweet.created_at) * -1;
			}
		};

		this.options = objectAssign(defaults, options);

		if (typeof this.options.sortBy !== 'function') {
			throw new TypeError(`sortBy value must be a function.`);
		}

		this.feeds = [];
		this.allTweets = [];
		this.filteredTweets = [];
		this.tweets = [];
	}

	/**
	 * Get or set the feeds to monitor
	 *
	 * @param {String} screenname
	 * @param {Object} options
	 * @api public
	 */
	feed(screenname, options) {
		if (!arguments.length) {
			return this._feed;
		}

		this._feed = this._feed || [];
		options = options || {};
		options.limit = options.limit || 12;

		this._feed.push({screenname, options});

		return this;
	}

	/**
	 * Start the birdwatch process.
	 *
	 * @api public
	 */
	async start() {
		const self = this;

		await getPort().then(port => {
			if (self.options.port === 0) {
				this.options.port = port;
			}
		});

		if (!this.feed() || this.feed().length === 0) {
			throw new Error('You must supply at least one feed to Birdwatch');
		}

		// ensure we have Twitter Credentials via environment variables when not using testData
		if (!self.options.testData && !process.env.CONSUMER_KEY || !process.env.CONSUMER_SECRET || !process.env.ACCESS_TOKEN || !process.env.ACCESS_TOKEN_SECRET) {
			throw new Error('Twitter credentials must be set via environment variables. See README.md for setup information.');
		}

		report.logStartMessage(self.options.refreshTime, self);

		await Promise.all(this.feed().map(feed => {
			const options = objectAssign({}, self.options, feed.options);

			if (!feed.screenname) {<commit_msg>tweaks<commit_after>require('dotenv').config({path: '../.env', silent: true});

import {EventEmitter} from 'events';

import objectAssign from 'object-assign';
import hashRegex from 'hash-regex';
import isRegexp from 'is-regexp';
import getPort from 'get-port';
import report from './report';

export default class Birdwatch {
	/**
	 * Initialize a new Birdwatch
	 *
	 * @param {Object} options
	 * @api public
	 */
	constructor(options) {
		const defaults = {
			logReports: true,
			server: true,
			port: 8417,
			testData: false,
			refreshTime: 600,
			url: '/birdwatch/tweets',
			cacheDir: `${__dirname}/cache`,
			sortBy: tweet => {
				return new Date(tweet.created_at) * -1;
			}
		};

		this.options = objectAssign(defaults, options);

		if (typeof this.options.sortBy !== 'function') {
			throw new TypeError(`sortBy value must be a function.`);
		}

		this.feeds = [];
		this.allTweets = [];
		this.filteredTweets = [];
		this.tweets = [];
	}

	/**
	 * Get or set the feeds to monitor
	 *
	 * @param {String} screenname
	 * @param {Object} options
	 * @api public
	 */
	feed(screenname, options) {
		if (!arguments.length) {
			return this._feed;
		}

		this._feed = this._feed || [];
		options = options || {};
		options.limit = options.limit || 12;

		this._feed.push({screenname, options});

		return this;
	}

	/**
	 * Start the birdwatch process.
	 *
	 * @api public
	 */
	async start() {
		const self = this;

		await getPort().then(port => {
			if (self.options.port === 0) {
				this.options.port = port;
			}
		});

		if (!this.feed() || this.feed().length === 0) {
			throw new Error('You must supply at least one feed to Birdwatch');
		}

		report.logStartMessage(self.options.refreshTime, self);

		await Promise.all(this.feed().map(feed => {
			const options = objectAssign({}, self.options, feed.options);

			if (!feed.screenname) {
{'fraction_non_alphanumeric': 0.1549158331300317, 'fraction_numerical': 0.005855086606489388, 'mean_word_length': 3.343220338983051, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2699656', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1317, 'n_words': 351}