<commit_before>'use strict';

const co = require('co');
const secrets = require('./secrets');
const db = require('./db');
const tw = require('./tw');
const discord = require('./discord');

const main = (event, callback) => {
  co(function* () {
    try {
      let SECRETS = yield secrets.getSecrets();

      let token = yield tw.getOAuthToken(SECRETS.twitter);
      let accounts = yield db.getAccounts();

      for (let account of accounts) {
        let screen_name = account.screen_name;
        let since_id = account.since_id;
        let exclude_replies = account.exclude_replies;

        let tweets = yield tw.getTweets(token, screen_name, since_id, exclude_replies, SECRETS.twitter);
        console.log('number of tweets:', tweets.length);

        // we want to process from oldest tweet to newest
        for (let tweet of tweets.reverse()) {
          if (tweet.id_str > since_id) {
            since_id = tweet.id_str
          }
          yield discord.post(tweet, SECRETS.discord);
        }
        if (tweets.length) {
          yield db.putAccount(screen_name, since_id, exclude_replies);
        }
      }

      callback(null, "finished!")
    }
    catch (e) {
      callback(e)
    }
  })
}

module.exports = { main };<commit_msg>stringify error message so its readable in cloudwatch<commit_after>'use strict';

const co = require('co');
const secrets = require('./secrets');
const db = require('./db');
const tw = require('./tw');
const discord = require('./discord');

const main = (event, callback) => {
  co(function* () {
    try {
      let SECRETS = yield secrets.getSecrets();

      let token = yield tw.getOAuthToken(SECRETS.twitter);
      let accounts = yield db.getAccounts();

      for (let account of accounts) {
        let screen_name = account.screen_name;
        let since_id = account.since_id;
        let exclude_replies = account.exclude_replies;

        let tweets = yield tw.getTweets(token, screen_name, since_id, exclude_replies, SECRETS.twitter);
        console.log('number of tweets:', tweets.length);

        // we want to process from oldest tweet to newest
        for (let tweet of tweets.reverse()) {
          if (tweet.id_str > since_id) {
            since_id = tweet.id_str
          }
          yield discord.post(tweet, SECRETS.discord);
        }
        if (tweets.length) {
          yield db.putAccount(screen_name, since_id, exclude_replies);
        }
      }

      callback(null, "finished!")
    }
    catch (e) {
      callback(JSON.stringify(e))
    }
  })
}

module.exports = { main };
{'fraction_non_alphanumeric': 0.12577881619937695, 'fraction_numerical': 0.0, 'mean_word_length': 2.4952380952380953, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2436880', 'n_tokens_mistral': 802, 'n_tokens_neox': 776, 'n_words': 199}