This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-professors-list.js
52 lines (43 loc) · 1.75 KB
/
build-professors-list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const {JSDOM} = require('jsdom');
const fetch = require('node-fetch');
function fetchDOM(url) {
return fetch(url)
.then(response => response.text())
.then(text => new JSDOM(text).window.document)
}
async function buildProfessorsList() {
const entries = await Promise.all((await Promise.all([1, 2, 3]
.map(async page =>
fetchDOM('https://www.hft-stuttgart.de/personenverzeichnis?' +
'tx_solr[filter][0]=role%3AProfessor%2Fin' +
'&tx_solr[page]=' +
page)
)))
.flatMap(dom => new Array(...dom.querySelectorAll('table tr td:first-child a'))
.map(element => element.getAttribute('href')))
.map(async prof => {
const dom = await fetchDOM('https://www.hft-stuttgart.de' + prof);
const tableRows = new Array(...dom.querySelector('.person-directory-columns').children);
const getTableContent = (title) => {
const row = tableRows
.find(el => el.querySelector('.col-3').textContent.trim() === title);
if (!row) return;
const text = row.querySelector('.col-9').textContent.trim();
if (!text || text === '') return;
return text.replace(/\s+/g, ' ');
};
let room = getTableContent('Büro:');
if (room && room.indexOf('Raum ') === 0) room = room.substring(5);
return {
name: dom.querySelector('.text-center > h1').textContent.trim(),
phone: getTableContent('Telefon:'),
email: getTableContent('E-Mail:'),
time: getTableContent('Sprechzeiten:'),
room
}
}));
const getLastName = (name) => name.substring(name.lastIndexOf(' ') + 1);
entries.sort((a, b) => getLastName(a.name).localeCompare(getLastName(b.name)));
console.log(JSON.stringify(entries, null, 2))
}
buildProfessorsList();