Newer
Older
console.time("Process");
var request = require("request");
var mongo = require("mongodb").MongoClient;
var ObjectID = require("mongodb").ObjectID;
var mongoUrl = "mongodb://localhost:3001/meteor";
var params = ["programme", "period", "year", "ects", "location", "courseLanguage", "courseType"];
mongo.connect(mongoUrl, function (err, db) {
db.collection("filters").drop();
db.close();
});
var getData = function (lang, param, sortCounter) {
var url = "https://eddiprod.au.dk/EDDI/webservices/CourseCatalogService2.cfc?method=getValueList&list=" + param + "&lang=" + lang;
//console.log("Getting data for '"+param+"' with language '"+lang+"'");
//console.log(url);
request({
url: url,
json: true
}, function (e, res, json) {
var obj = {};
//console.log(json);
json.listItems.forEach(function (item) {
arr.push({id: item.id, name: item[json.listName]});
});
if (param == "courseLanguage") {
json.listName = "instructionLanguage"
}
obj["name"] = json.listName;
obj["lang"] = lang;
obj["list"] = arr;
obj["sorting"] = sortCounter;
if(json.listName == "year") obj["default"] = ["2015", "2016"];
else obj["default"] = [];
mongo.connect(mongoUrl, function (err, db) {
//db.collection("filters").drop();
db.collection("filters").insert(obj, function (err, docs) {
db.close();
};
lang.forEach(function (lang) {
params.forEach(function (param) {
getData(lang, param, sortCounter);
sortCounter = sortCounter + 10;