}, function (err, results) {
   if (err) {
     console.log(err);
   } else {
     // cache for 2 hours (in ms)
     cache.set('mwdev.wikimediaRepos', results, 3600 * 2000);
     callback( results );
   }
 })
Exemple #2
0
  wget.on('close', (code) => {
    if (code === 0) {
      let ouData = { codeUnite: codeUnite, labintelUrl: 'https://web-ast.dsi.cnrs.fr/l3c/owa/structure.infos_admin?p_lab=' + codeUnite + '&p_origine_appel=un' };
      // ISO-8859-1 => UTF-8
      rawOuData = '' + encoding.convert(rawOuData, 'UTF-8', 'ISO-8859-1'); // not working ...

      let $ = cheerio.load(rawOuData, {
        normalizeWhitespace: false,
        decodeEntities: false
      });

      $('ul li').each(function(i, elem) {
        let section = $(elem).find('b').text().trim();
        section = parseOukey(section);
        $(elem).find('b').remove();
        let values = $(this).text().trim().split('\n')
          .map(function (el) {
            return el.trim();
          })
          .filter(function (el) {
            return el != 'Principal :';
          });
        
        if (section == 'effectif') {
          values = parseEffectif(values);
        }

        ouData[section] = values;
      });      

      labintelCache.set(codeUnite, ouData);

      return cb(null, ouData);
    } else {
      return cb(new Error(rawErr));
    }
  });