This repository was archived by the owner on Jan 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-professors-list.js
More file actions
53 lines (44 loc) · 2.08 KB
/
build-professors-list.js
File metadata and controls
53 lines (44 loc) · 2.08 KB
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
53
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][role_2]=role%3AProfessor%3Ain' +
'&tx_solr[page]=' +
page)
)))
.flatMap(dom => [...(dom.querySelector(".staff-list").querySelectorAll("tr"))])
.filter(element => element.querySelector('a'))
.map(element => element.querySelector('a').getAttribute('href'))
.map(async prof => {
const dom = await fetchDOM('https://www.hft-stuttgart.de' + prof);
const tableRows = new Array(...dom.querySelectorAll('.row'));
const getTableContent = (title) => {
const row = tableRows
.find(el => el.querySelector('.col-5') && el.querySelector('.col-5').textContent.trim() === title);
if (!row) return;
const text = row.querySelector('.col-7').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('.person-directory__header__headlines > 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();