<commit_before>const low = require("lowdb");
const dataDb = low('./data/datadb.json');
const Requester = require('../controllers/requester');
const Parser = require('../controllers/parser');

const TIME_SECOND = 1000;
const TIME_MIN = 60 * TIME_SECOND;
const TIME_HOUR = 60 * TIME_MIN;

var initialiseDataSet = function initialiseDataSet() {

  // Initialise app
  // obtains ids
  // announcements, forum, webcast, files
}

var retrieveDataSet = function retrieveDataSet() {
  updateLoop(function() {
    console.log("fetching data");
    Parser.getAnnouncements();
  });
}

var updateLoop = function updateLoop(functionToRun) {
  functionToRun();
  setTimeout(requestLoop, 5 * TIME_MIN);
}

var TaskRunner = {
  init: function() {
    initialiseDataSet();
  },

  run: function() {
    retrieveDataSet();
  }

};


module.exports = TaskRunner;<commit_msg>Use promise for api request, taskrunner<commit_after>const low = require("lowdb");
const userDb = low('./data/userdb.json');
const dataDb = low('./data/datadb.json');
const Requester = require('../controllers/requester');
const Parser = require('../controllers/parser');


const TIME_SECOND = 1000;
const TIME_MIN = 60 * TIME_SECOND;
const TIME_HOUR = 60 * TIME_MIN;


var updateLoop = function updateLoop(functionToRun) {
  functionToRun();
  setTimeout(updateLoop, 5 * TIME_MIN, functionToRun);
}

var TaskRunner = {
  init: function() {
    updateModuleIds();
    // Initialise app
    // obtains ids
    // announcements, forum, webcast, files
  },

  run: function() {
    updateLoop(Parser.getAnnouncements);
  }
};

var updateModuleIds = function updateModuleIds() {
  // Obtain data from IVLE
  Requester.requestJson("Modules", {
    "Duration": "0",
    "IncludeAllInfo": "false"
  }).then(
    function(data) {
      let modulesObj = filterModuleIds(data);
      storeModuleIds(modulesObj);
    },
    function(error) {
      console.error(error);
    }
  );

  function filterModuleIds(data) {
    let modulesArray = data["Results"];
    let modulesObj = {};

    modulesArray.forEach(function(moduleObj, index, array) {
      let moduleId = moduleObj["ID"];
      modulesObj[moduleId] = {};
    });

    return modulesObj;
  }

  function storeModuleIds(modulesObj) {
    userDb.set("modules", modulesObj);
  }
}

module.exports = TaskRunner;
{'fraction_non_alphanumeric': 0.14019904803115535, 'fraction_numerical': 0.008221549112938122, 'mean_word_length': 3.846960167714885, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '4706670', 'n_tokens_mistral': 740, 'n_tokens_neox': 723, 'n_words': 159}