<commit_before>var fs = require('fs');
var Trello = require("node-trello");
var config = require('./config');

var trello = new Trello(config.key, config.token);

var hr = '___';
var h1 = '#';
var h3 = '###';
var h4 = '####';
var h5 = '#####';
var h6 = '######';
var br = '\n';
var tab = '&nbsp;&nbsp;&nbsp;&nbsp;';

var currentWaitTime = 0;
var DELTA_WAIT_TIME = 150; //Wait 15 seconds between each interval so we're not attacking Trello's API

var numDays = process.argv[2];

//So we can limit the amount of cards we retrieve, we'll need to store the end date
var endDate = new Date();
endDate.setDate(endDate.getDate() - numDays);

//Make sure numDays is a number >= 1
if (numDays && !isNaN(numDays) && numDays > 0) {
  createMarkdowns()
} else {
  console.log('Number of days to search must be a positive number greater than 0.');
  console.log('Usage: node trello-json-to-markdown.js \<number_of_days_to_search\>');
}

/**
 * This will generate the markdown files for each board and
 * cards within each board
 *
 */
function createMarkdowns() {

  config.boards.forEach(function (boardId) {
    trello.get('/1/boards/' + boardId + '?cards=all&lists=all&members=all&member_fields=all&checklists=all&fields=all', function (error, boardJSON) {
      if (error) {
        console.log(error);
      }
      var boardName = boardJSON.name;
      if (boardName) {

        var boardShortUrl = boardJSON.shortUrl;
        var cards = boardJSON.cards;

        var boardDirectory = boardName + '/';
        var cardDirectory = boardName + '-cards/';
        //Full card ID = boardName-cardNumber
        var cardPrefix = boardName + '-';
        var tableOfContentsFile = boardDirectory + boardName + '.md';

        //Set the title of the table of contents the the board name (and link the board name to the board)
        var tableOfContents = h1 + '[' + boardName + '](' + boardShortUrl + ')' + br;

        //Make the card and board directory if they does not already exist
        if (!fs.existsSync(boardDirectory)) {
          fs.mkdirSync(boardDirectory);
        }

        if (!fs.existsSync(boardDirectory + cardDirectory)) {
          fs.mkdirSync(boardDirectory + cardDirectory);
        }

        //Sort cards based on the most recent activity
        //We're sorting in reversed order since later dates are 'larger'
        //so they will be put in later into the array if not sorted in reverse
        cards.sort(function (card1, card2) {
          return Date.parse(card2.dateLastActivity) - Date.parse(card1.dateLastActivity);
        });

        cards.forEach(function (card) {
          var idShort = card.idShort;
          var cardFullId = cardPrefix + idShort;
          var cardFilePath = cardDirectory + cardFullId + '.md';
          var name = card.name;

          //Add the card to the table of contents and link the card to the card's markdown file
          tableOfContents += h3 + '[Card #' + idShort + '](' + cardFilePath + ')' + br;
          tableOfContents += '[' + cardFullId + '](' + cardFilePath + ')' + br;
          tableOfContents += h6 + name + br;
          tableOfContents += '*Last Modified: ' + (new Date(card.dateLastActivity)).toUTCString() + '*' + br;
          tableOfContents += hr + br;
        });

        cards = cards.filter(function (card) {
          return Date.parse(card.dateLastActivity) >= endDate;
        });

        cards.forEach(function (card) {
          setTimeout(function () {
            createCardMarkdown(card, cardPrefix, cardDirectory, boardDirectory);
          }, currentWaitTime);
          currentWaitTime += DELTA_WAIT_TIME;
        });

        //Write the table of contents to its markdown file
        fs.writeFileSync(tableOfContentsFile, tableOfContents);
      }
    });
  });
}

function createCardMarkdown(card, cardPrefix, cardDirectory, boardDirectory, retry) {
  var id = card.id;
  trello.get('/1/card/' + id + '?actions=all&actions_limit=1000&members=true&member_fields=all&checklists=all&checklist_fields=all', function (error, cardJSON) {
    if (error) {
      if (retry) {
        console.log('An error has occurred when gathering actions for ' + cardPrefix + '-' + card.idShort);
        console.log('Retrying to get the actions now...');
        createCardMarkdown(card, cardPrefix, cardDirectory, boardDirectory, false);
      } else {

      }<commit_msg>Fixed lint issues, and completed failed request messages<commit_after>var fs = require('fs');
var Trello = require("node-trello");
var config = require('./config');

var trello = new Trello(config.key, config.token);

var hr = '___';
var h1 = '#';
var h3 = '###';
var h4 = '####';
var h5 = '#####';
var h6 = '######';
var br = '\n';
var tab = '&nbsp;&nbsp;&nbsp;&nbsp;';

var currentWaitTime = 0;
var DELTA_WAIT_TIME = 150; //Wait 15 seconds between each interval so we're not attacking Trello's API

var numDays = process.argv[2];

//So we can limit the amount of cards we retrieve, we'll need to store the end date
var endDate = new Date();
endDate.setDate(endDate.getDate() - numDays);

//Make sure numDays is a number >= 1
if (numDays && !isNaN(numDays) && numDays > 0) {
  createMarkdowns();
} else {
  console.log('Number of days to search must be a positive number greater than 0.');
  console.log('Usage: node trello-json-to-markdown.js \<number_of_days_to_search\>');
}

/**
 * This will generate the markdown files for each board and
 * cards within each board
 *
 */
function createMarkdowns() {

  config.boards.forEach(function (boardId) {
    trello.get('/1/boards/' + boardId + '?cards=all&lists=all&members=all&member_fields=all&checklists=all&fields=all', function (error, boardJSON) {
      if (error) {
        console.log(error);
      }
      var boardName = boardJSON.name;
      if (boardName) {

        var boardShortUrl = boardJSON.shortUrl;
        var cards = boardJSON.cards;

        var boardDirectory = boardName + '/';
        var cardDirectory = boardName + '-cards/';
        //Full card ID = boardName-cardNumber
        var cardPrefix = boardName + '-';
        var tableOfContentsFile = boardDirectory + boardName + '.md';

        //Set the title of the table of contents the the board name (and link the board name to the board)
        var tableOfContents = h1 + '[' + boardName + '](' + boardShortUrl + ')' + br;

        //Make the card and board directory if they does not already exist
        if (!fs.existsSync(boardDirectory)) {
          fs.mkdirSync(boardDirectory);
        }

        if (!fs.existsSync(boardDirectory + cardDirectory)) {
          fs.mkdirSync(boardDirectory + cardDirectory);
        }

        //Sort cards based on the most recent activity
        //We're sorting in reversed order since later dates are 'larger'
        //so they will be put in later into the array if not sorted in reverse
        cards.sort(function (card1, card2) {
          return Date.parse(card2.dateLastActivity) - Date.parse(card1.dateLastActivity);
        });

        cards.forEach(function (card) {
          var idShort = card.idShort;
          var cardFullId = cardPrefix + idShort;
          var cardFilePath = cardDirectory + cardFullId + '.md';
          var name = card.name;

          //Add the card to the table of contents and link the card to the card's markdown file
          tableOfContents += h3 + '[Card #' + idShort + '](' + cardFilePath + ')' + br;
          tableOfContents += '[' + cardFullId + '](' + cardFilePath + ')' + br;
          tableOfContents += h6 + name + br;
          tableOfContents += '*Last Modified: ' + (new Date(card.dateLastActivity)).toUTCString() + '*' + br;
          tableOfContents += hr + br;
        });

        cards = cards.filter(function (card) {
          return Date.parse(card.dateLastActivity) >= endDate;
        });

        cards.forEach(function (card) {
          setTimeout(function () {
            createCardMarkdown(card, cardPrefix, cardDirectory, boardDirectory);
          }, currentWaitTime);
          currentWaitTime += DELTA_WAIT_TIME;
        });

        //Write the table of contents to its markdown file
        fs.writeFileSync(tableOfContentsFile, tableOfContents);
      }
    });
  });
}

function createCardMarkdown(card, cardPrefix, cardDirectory, boardDirectory, retry) {
  var id = card.id;
  trello.get('/1/card/' + id + '?actions=all&actions_limit=1000&members=true&member_fields=all&checklists=all&checklist_fields=all', function (error, cardJSON) {
    if (error) {
      if (retry) {
        console.log('An error has occurred when gathering actions for ' + cardPrefix + card.idShort);
        console.log('Retrying to get the actions now...');
        createCardMarkdown(card, cardPrefix, cardDirectory, boardDirectory, false);
      } else {
        console.log('Requesting ' + cardPrefix + card.idShort + ' failed again.');
        console.log('It will not be requested again.');
      }
{'fraction_non_alphanumeric': 0.12843004948268105, 'fraction_numerical': 0.006297795771479982, 'mean_word_length': 2.8315381301163294, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7290249', 'n_tokens_mistral': 2661, 'n_tokens_neox': 2554, 'n_words': 766}