<commit_before>var Trello = require("node-trello");
var dateFormat = require('dateformat');
var async = require('async');
var Table = require('cli-table');
var moment = require('moment-timezone');

// to get auth token
var t = new Trello(process.env.appkey, process.env.authtoken);
var cardops = [];

var dryRun = true;
var cherry_pick_label = 'orange';
var personal_label = 'blue';
var process_label = 'green';
var work_label = 'yellow';
var periodic_label = 'purple';

var boards = {
  daily: null,
  backlog_personal: null,
  backlog_work: null,
  history_board: null,
  periodic_board: null,
  someday: null,
  shopping: null,
};
var lists = {
  inbox: null,
  today: null,
  done: null,
  weekly_goals: null,
  monthly_goals: null,
  monthly_sprints: null,
  backlog: {
    work_backlog: null,
    personal_backlog: null,
  },
  periodic: {
    often: null,
    weekly: null,
    biweekmonthly: null,
    quarteryearly: null,
  },
  somedaymaybe: null,
  shopping: {
    needtoget: null,
    purchased: null,
    pantry: null,
    refrigerator: null,
  },
};
// var daily, backlog_personal, backlog_work;

exports.boards = boards;
exports.lists = lists;

var history_this_week, history_this_week_goals;
var history_this_month_goals, history_this_month_sprints;
var periodic_often, periodic_weekly, periodic_biweekmonthly;
var periodic_quarteryearly;

var would_move_summary = new Table({ head: ["", "Items"]});
var move_destination = {};

var would_move = function(item,dest) {
  if (!(dest in move_destination)) {
    move_destination[dest] = [];
  }
  move_destination[dest].push(item);
}
var would_move_to_list = function(item, board, list) {
  dest = board.name + " - " + list.name;
  if (!(dest in move_destination)) {
    move_destination[dest] = [];
  }
  move_destination[dest].push(item);
}

var would_copy_summary = new Table({ head: ["", "Items"]});
var copy_destination = {};
var would_copy_to_list = function(item, board, list) {
  dest = board.name + " - " + list.name;
  if (!(dest in copy_destination)) {
    copy_destination[dest] = [];
  }
  copy_destination[dest].push(item);
}

exports.summarize_changes = function() {
console.log("tops.summary");
  for (var dest in move_destination) {
    var d = {};
    d[dest] = move_destination[dest].join('\n');
    would_move_summary.push(d);
  }
  if (would_move_summary.length > 0) {
    console.log("would move items to:")
    console.log(would_move_summary.toString());
  } else {
    console.log("No changes");
  }

  for (var dest in copy_destination) {
    var d = {};
    d[dest] = copy_destination[dest].join('\n');
    would_copy_summary.push(d);
  }
  if (would_copy_summary.length > 0) {
    console.log("would copy items to:")
    console.log(would_copy_summary.toString());
  } else {
    console.log("No changes");
  }
}

exports.preparetoday = function(cb) {
  async.series([
    function(cb) {
      console.log("move items from Inbox to backlog based on label color");
      t.get("/1/lists/" + lists.inbox.id + "/cards", function(err, data) {
        if (err) return cb(err);

        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          var board = null, list = null;
          if (card_has_label(data[i], periodic_label)) {
            // console.log("would move periodic");
            movePeriodic(data[i]);
          } else if (card_has_label(data[i],personal_label)) {
            // console.log("move to Backlog (personal)/Backlog");
            board = boards.backlog_personal;
            list = lists.backlog.personal_backlog;
          } else if (card_has_label(data[i],process_label)) {
            // console.log("move to Backlog (personal)/Backlog");
            board = boards.backlog_personal;
            list = lists.backlog.personal_backlog;
          } else if (card_has_label(data[i],work_label)) {
            // console.log("move to Backlog (work)/Backlog");
            board = boards.backlog_work;
            list = lists.backlog.work_backlog;
          }
          if (board && list) {
            would_move_to_list(data[i].name, board, list);
            cardops.push(moveCard(data[i], board, list, 'top'));
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("move items from Today to backlog based on label color");
      t.get("/1/lists/" + lists.today.id + "/cards", function(err, data) {
        if (err) return cb(err);

        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          var board = null, list = null;
          if (card_has_label(data[i], periodic_label)) {
            // console.log("would move periodic");
            movePeriodic(data[i]);

          } else if (card_has_label(data[i], personal_label)) {
            // console.log("move to Backlog (personal)/Backlog");
            board = boards.backlog_personal;
            list = lists.backlog.personal_backlog;
          } else if (card_has_label(data[i], process_label)) {
            // console.log("move to Backlog (personal)/Backlog");
            board = boards.backlog_personal;
            list = lists.backlog.personal_backlog;
          } else if (card_has_label(data[i], work_label)) {
            // console.log("move to Backlog (work)/Backlog");
            board = boards.backlog_work;
            list = lists.backlog.work_backlog;
          }
          if (board && list) {
            would_move_to_list(data[i].name, board, list);
            cardops.push(moveCard(data[i], board, list, 'top'));
          }
        }
        cb(null);
      });
    },
  ], cb);
}

exports.maintenance = function(cb) {
  async.series([
    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.inbox.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.today.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.backlog.personal_backlog.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },

    // cherry pick
    function(cb) {
      console.log("move all cherry picked items from Personal backlog to Kanban Today");
      t.get("/1/lists/" + lists.backlog.personal_backlog.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Work backlog to Kanban Today");
      t.get("/1/lists/" + lists.backlog.work_backlog.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Periodic often to Kanban Today");
      t.get("/1/lists/" + lists.periodic.often.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Periodic weekly to Kanban Today");
      t.get("/1/lists/" + lists.periodic.weekly.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Periodic bi-weekly/monthly to Kanban Today");
      t.get("/1/lists/" + lists.periodic.biweekmonthly.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Periodic quarterly/yearly to Kanban Today");
      t.get("/1/lists/" + lists.periodic.quarteryearly.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all someday/maybe items from Inbox to someday/maybe");
      t.get("/1/lists/" + lists.inbox.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_title_starts_with(data[i], "^\\? ")) {
            would_move_to_list(data[i].name, boards.someday, lists.somedaymaybe);
            cardops.push(moveCardAndTruncateTitle(data[i], boards.someday,
                                                  lists.somedaymaybe,
                                                  "top", 2));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Shopping purchased to Shopping Need to get");
      t.get("/1/lists/" + lists.shopping.purchased.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.shopping, lists.shopping.needtoget);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.shopping, lists.shopping.needtoget,
                                                "top", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Shopping pantry to Shopping Need to get");
      t.get("/1/lists/" + lists.shopping.pantry.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.shopping, lists.shopping.needtoget);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.shopping, lists.shopping.needtoget,
                                                "top", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Shopping refrigerator to Shopping Need to get");
      t.get("/1/lists/" + lists.shopping.refrigerator.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.shopping, lists.shopping.needtoget);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.shopping, lists.shopping.needtoget,
                                                "top", cherry_pick_label));
          }
        }
        cb(null);
      });

    },

  ], cb);
}

exports.init = function(_dryRun, cb) {
  dryRun = _dryRun;
  async.series([
    // get board info
    function(cb) {
      console.log("Get boards");
      t.get("/1/members/me/boards", function(err, data) {
        if (err) return cb(err);
        var i;
        for (i = 0; i < data.length; i++) {
          // console.log(data[i].name);
          if (data[i].name == 'Kanban daily/weekly') {
            boards.daily = data[i];
          } else if (data[i].name == 'Backlog (Personal)') {
            boards.backlog_personal = data[i];
            // console.log(data[i]);
          } else if (data[i].name == 'Backlog (work)') {
            boards.backlog_work = data[i];
          } else if (data[i].name == 'History 2016') {
            boards.history_board = data[i];
          } else if (data[i].name == 'Periodic board') {
            boards.periodic_board = data[i];
          } else if (data[i].name == 'Someday/Maybe') {
            boards.someday = data[i];
          } else if (data[i].name == 'Shopping') {
            boards.shopping = data[i];
            // console.log(data[i]);
          // } else if (data[i].name != '') {
            // console.log(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("Get lists from Kanban daily board");
      // console.log(daily);
      // console.log(daily.id);
      t.get("/1/boards/" + boards.daily.id  + "/lists", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          if (data[i].name == 'Inbox') {
            lists.inbox = data[i];
          } else if (data[i].name == 'Today') {
            lists.today = data[i];
          } else if (data[i].name == 'Done this week') {
            lists.done = data[i];
          } else if (data[i].name == 'Weekly Goals') {
            lists.weekly_goals = data[i];
          } else if (data[i].name == 'Monthly Goals') {
            lists.monthly_goals = data[i];
          } else if (data[i].name == 'Monthly Sprints') {
            lists.monthly_sprints = data[i];
          // } else {
          //   console.log(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("Get lists from Someday/Maybe");
      t.get("/1/boards/" + boards.someday.id  + "/lists", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          if (data[i].name == 'Maybe') {
            lists.somedaymaybe = data[i];
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("Get lists from Backlog(personal)");
      t.get("/1/boards/" + boards.backlog_personal.id  + "/lists", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          if (data[i].name == 'Backlog') {
            lists.backlog.personal_backlog = data[i];
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("Get lists from Backlog(work)");
      t.get("/1/boards/" + boards.backlog_work.id  + "/lists", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          if (data[i].name == 'Backlog') {
            lists.backlog.work_backlog = data[i];
          }<commit_msg>add creation dates to titles in someday/maybe lists<commit_after>var Trello = require("node-trello");
var dateFormat = require('dateformat');
var async = require('async');
var Table = require('cli-table');
var moment = require('moment-timezone');

// to get auth token
var t = new Trello(process.env.appkey, process.env.authtoken);
var cardops = [];

var dryRun = true;
var cherry_pick_label = 'orange';
var personal_label = 'blue';
var process_label = 'green';
var work_label = 'yellow';
var periodic_label = 'purple';

var boards = {
  daily: null,
  backlog_personal: null,
  backlog_work: null,
  history_board: null,
  periodic_board: null,
  someday: null,
  shopping: null,
};
var lists = {
  inbox: null,
  today: null,
  done: null,
  weekly_goals: null,
  monthly_goals: null,
  monthly_sprints: null,
  backlog: {
    work_backlog: null,
    personal_backlog: null,
  },
  periodic: {
    often: null,
    weekly: null,
    biweekmonthly: null,
    quarteryearly: null,
  },
  somedaymaybe: {
    maybe: null,
    productideation: null,
    writing: null,
    appsiwouldlike: null,
    somedayspend: null,
  },
  shopping: {
    needtoget: null,
    purchased: null,
    pantry: null,
    refrigerator: null,
  },
};
// var daily, backlog_personal, backlog_work;

exports.boards = boards;
exports.lists = lists;

var history_this_week, history_this_week_goals;
var history_this_month_goals, history_this_month_sprints;
var periodic_often, periodic_weekly, periodic_biweekmonthly;
var periodic_quarteryearly;

var would_move_summary = new Table({ head: ["", "Items"]});
var move_destination = {};

var would_move = function(item,dest) {
  if (!(dest in move_destination)) {
    move_destination[dest] = [];
  }
  move_destination[dest].push(item);
}
var would_move_to_list = function(item, board, list) {
  dest = board.name + " - " + list.name;
  if (!(dest in move_destination)) {
    move_destination[dest] = [];
  }
  move_destination[dest].push(item);
}

var would_copy_summary = new Table({ head: ["", "Items"]});
var copy_destination = {};
var would_copy_to_list = function(item, board, list) {
  dest = board.name + " - " + list.name;
  if (!(dest in copy_destination)) {
    copy_destination[dest] = [];
  }
  copy_destination[dest].push(item);
}

exports.summarize_changes = function() {
console.log("tops.summary");
  for (var dest in move_destination) {
    var d = {};
    d[dest] = move_destination[dest].join('\n');
    would_move_summary.push(d);
  }
  if (would_move_summary.length > 0) {
    console.log("would move items to:")
    console.log(would_move_summary.toString());
  } else {
    console.log("No changes");
  }

  for (var dest in copy_destination) {
    var d = {};
    d[dest] = copy_destination[dest].join('\n');
    would_copy_summary.push(d);
  }
  if (would_copy_summary.length > 0) {
    console.log("would copy items to:")
    console.log(would_copy_summary.toString());
  } else {
    console.log("No changes");
  }
}

exports.preparetoday = function(cb) {
  async.series([
    function(cb) {
      console.log("move items from Inbox to backlog based on label color");
      t.get("/1/lists/" + lists.inbox.id + "/cards", function(err, data) {
        if (err) return cb(err);

        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          var board = null, list = null;
          if (card_has_label(data[i], periodic_label)) {
            // console.log("would move periodic");
            movePeriodic(data[i]);
          } else if (card_has_label(data[i],personal_label)) {
            // console.log("move to Backlog (personal)/Backlog");
            board = boards.backlog_personal;
            list = lists.backlog.personal_backlog;
          } else if (card_has_label(data[i],process_label)) {
            // console.log("move to Backlog (personal)/Backlog");
            board = boards.backlog_personal;
            list = lists.backlog.personal_backlog;
          } else if (card_has_label(data[i],work_label)) {
            // console.log("move to Backlog (work)/Backlog");
            board = boards.backlog_work;
            list = lists.backlog.work_backlog;
          }
          if (board && list) {
            would_move_to_list(data[i].name, board, list);
            cardops.push(moveCard(data[i], board, list, 'top'));
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("move items from Today to backlog based on label color");
      t.get("/1/lists/" + lists.today.id + "/cards", function(err, data) {
        if (err) return cb(err);

        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          var board = null, list = null;
          if (card_has_label(data[i], periodic_label)) {
            // console.log("would move periodic");
            movePeriodic(data[i]);

          } else if (card_has_label(data[i], personal_label)) {
            // console.log("move to Backlog (personal)/Backlog");
            board = boards.backlog_personal;
            list = lists.backlog.personal_backlog;
          } else if (card_has_label(data[i], process_label)) {
            // console.log("move to Backlog (personal)/Backlog");
            board = boards.backlog_personal;
            list = lists.backlog.personal_backlog;
          } else if (card_has_label(data[i], work_label)) {
            // console.log("move to Backlog (work)/Backlog");
            board = boards.backlog_work;
            list = lists.backlog.work_backlog;
          }
          if (board && list) {
            would_move_to_list(data[i].name, board, list);
            cardops.push(moveCard(data[i], board, list, 'top'));
          }
        }
        cb(null);
      });
    },
  ], cb);
}

exports.maintenance = function(cb) {
  async.series([
    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.inbox.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.today.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.backlog.personal_backlog.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },

    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.somedaymaybe.maybe.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.somedaymaybe.productideation.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.somedaymaybe.writing.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.somedaymaybe.appsiwouldlike.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("add creation date to title (if doesn't exist)");
      t.get("/1/lists/" + lists.somedaymaybe.somedayspend.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (!card_has_date(data[i]) && !card_has_periodic(data[i])) {
            addDateToName(data[i]);
          }
        }
        cb(null);
      });
    },

    // cherry pick
    function(cb) {
      console.log("move all cherry picked items from Personal backlog to Kanban Today");
      t.get("/1/lists/" + lists.backlog.personal_backlog.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Work backlog to Kanban Today");
      t.get("/1/lists/" + lists.backlog.work_backlog.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Periodic often to Kanban Today");
      t.get("/1/lists/" + lists.periodic.often.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Periodic weekly to Kanban Today");
      t.get("/1/lists/" + lists.periodic.weekly.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Periodic bi-weekly/monthly to Kanban Today");
      t.get("/1/lists/" + lists.periodic.biweekmonthly.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Periodic quarterly/yearly to Kanban Today");
      t.get("/1/lists/" + lists.periodic.quarteryearly.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.daily, lists.today);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.daily, lists.today,
                                                "bottom", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all someday/maybe items from Inbox to someday/maybe");
      t.get("/1/lists/" + lists.inbox.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_title_starts_with(data[i], "^\\? ")) {
            would_move_to_list(data[i].name, boards.someday, lists.somedaymaybe.maybe);
            cardops.push(moveCardAndTruncateTitle(data[i], boards.someday,
                                                  lists.somedaymaybe.maybe,
                                                  "top", 2));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Shopping purchased to Shopping Need to get");
      t.get("/1/lists/" + lists.shopping.purchased.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.shopping, lists.shopping.needtoget);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.shopping, lists.shopping.needtoget,
                                                "top", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Shopping pantry to Shopping Need to get");
      t.get("/1/lists/" + lists.shopping.pantry.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.shopping, lists.shopping.needtoget);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.shopping, lists.shopping.needtoget,
                                                "top", cherry_pick_label));
          }
        }
        cb(null);
      });

    },
    function(cb) {
      console.log("move all cherry picked items from Shopping refrigerator to Shopping Need to get");
      t.get("/1/lists/" + lists.shopping.refrigerator.id + "/cards", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          // console.log(data[i]);
          if (card_has_label(data[i], cherry_pick_label)) {
            would_move_to_list(data[i].name, boards.shopping, lists.shopping.needtoget);
            cardops.push(moveCardAndRemoveLabel(data[i], boards.shopping, lists.shopping.needtoget,
                                                "top", cherry_pick_label));
          }
        }
        cb(null);
      });

    },

  ], cb);
}

exports.init = function(_dryRun, cb) {
  dryRun = _dryRun;
  async.series([
    // get board info
    function(cb) {
      console.log("Get boards");
      t.get("/1/members/me/boards", function(err, data) {
        if (err) return cb(err);
        var i;
        for (i = 0; i < data.length; i++) {
          // console.log(data[i].name);
          if (data[i].name == 'Kanban daily/weekly') {
            boards.daily = data[i];
          } else if (data[i].name == 'Backlog (Personal)') {
            boards.backlog_personal = data[i];
            // console.log(data[i]);
          } else if (data[i].name == 'Backlog (work)') {
            boards.backlog_work = data[i];
          } else if (data[i].name == 'History 2016') {
            boards.history_board = data[i];
          } else if (data[i].name == 'Periodic board') {
            boards.periodic_board = data[i];
          } else if (data[i].name == 'Someday/Maybe') {
            boards.someday = data[i];
          } else if (data[i].name == 'Shopping') {
            boards.shopping = data[i];
            // console.log(data[i]);
          // } else if (data[i].name != '') {
            // console.log(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("Get lists from Kanban daily board");
      // console.log(daily);
      // console.log(daily.id);
      t.get("/1/boards/" + boards.daily.id  + "/lists", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          if (data[i].name == 'Inbox') {
            lists.inbox = data[i];
          } else if (data[i].name == 'Today') {
            lists.today = data[i];
          } else if (data[i].name == 'Done this week') {
            lists.done = data[i];
          } else if (data[i].name == 'Weekly Goals') {
            lists.weekly_goals = data[i];
          } else if (data[i].name == 'Monthly Goals') {
            lists.monthly_goals = data[i];
          } else if (data[i].name == 'Monthly Sprints') {
            lists.monthly_sprints = data[i];
          // } else {
          //   console.log(data[i]);
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("Get lists from Someday/Maybe");
      t.get("/1/boards/" + boards.someday.id  + "/lists", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          if (data[i].name == 'Maybe') {
            lists.somedaymaybe.maybe = data[i];
          } else if (data[i].name == 'Product ideation') {
            lists.somedaymaybe.productideation = data[i];
          } else if (data[i].name == 'Writing') {
            lists.somedaymaybe.writing = data[i];
          } else if (data[i].name == 'Apps I would like to write') {
            lists.somedaymaybe.appsiwouldlike = data[i];
          } else if (data[i].name == 'Someday/Maybe (spend $$)') {
            lists.somedaymaybe.somedayspend = data[i];
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("Get lists from Backlog(personal)");
      t.get("/1/boards/" + boards.backlog_personal.id  + "/lists", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          if (data[i].name == 'Backlog') {
            lists.backlog.personal_backlog = data[i];
          }
        }
        cb(null);
      });
    },
    function(cb) {
      console.log("Get lists from Backlog(work)");
      t.get("/1/boards/" + boards.backlog_work.id  + "/lists", function(err, data) {
        if (err) return cb(err);
        for (i = 0; i < data.length; i++) {
          if (data[i].name == 'Backlog') {
            lists.backlog.work_backlog = data[i];
          }
{'fraction_non_alphanumeric': 0.15672848824671123, 'fraction_numerical': 0.0028035367694630147, 'mean_word_length': 2.0372523333879156, 'pattern_counts': {'":': 0, '<': 48, '<?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': 44, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1145680', 'n_tokens_mistral': 12014, 'n_tokens_neox': 11775, 'n_words': 2423}