added: previous work

This commit is contained in:
Timo Henkensiefken 2024-12-06 19:42:52 +01:00
parent df601e40cd
commit 419a929047
4 changed files with 191 additions and 0 deletions

7
.ratpoisonrc Normal file
View File

@ -0,0 +1,7 @@
banish
#exec chromium --noerrdialogs --enable-features=OverlayScrollbar --start-maximized --kiosk ~/abfahrten-monitor/index.html --incognito --disable-translate
exec chromium --noerrdialogs --enable-features=OverlayScrollbar --user-data-dir="/home/bildschirm/.config/chromium/" --kiosk "http://bus.fs-et.de/InfoDisplay2_bussued.htm"
#exec chromium --noerrdialogs --enable-features=OverlayScrollbar --start-maximized --kiosk 'https://echtzeit.swu.de/' --incognito --disable-translate

99
fetchapi.js Normal file
View File

@ -0,0 +1,99 @@
const HEADER_ROW = false;
// Define the API URL
// const urlStop = 'https://api.swu.de/mobility/v1/stop/attributes/BaseData?StopNumber=1240&ContentScope=extended';
const urlDepartures = 'https://api.swu.de/mobility/v1/stop/passage/Departures?StopNumber=1240&Limit=10';
// const apiUrl = 'Departures.json';
// Make a GET request
function refreshData() {
fetch(urlDepartures)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
showAllDepsByTime(data);
})
.catch(error => {
console.error('Error:', error);
});
}
// Groups Departures into map by route
function groupDepartures(data) {
const routes = new Map();
for (let x of data.StopPassage.DepartureData) {
if (routes.has(x.RouteNumber)) {
routes.get(x.RouteNumber).push(x);
} else {
routes.set(x.RouteNumber, [x]);
}
}
return routes;
}
function showAllDepsByTime(data) {
const date = new Date(data.StopPassage.CurrentTimestamp);
document.getElementById('stationName').innerHTML = data.StopPassage.StopName;
document.getElementById('timeBox').innerHTML = date.toLocaleTimeString('de-DE');
const table = getTable(
[cell => cell.innerHTML = "Linie",
cell => cell.innerHTML = "Ziel",
cell => cell.innerHTML = "Abfahrt"],
[(cell, datap) => {cell.appendChild(getRouteImage(datap.RouteName));
cell.setAttribute("class", "cellRoute")},
(cell, datap) => {cell.innerHTML = datap.DepartureDirectionText;
cell.setAttribute("class", "cellDest")},
(cell, datap) => {cell.innerHTML = "" + Math.floor((datap.DepartureCountdown + datap.DepartureDeviation) / 60);
cell.setAttribute("class", "cellTime")}],
data.StopPassage.DepartureData.filter(departure => departure.RouteName != '-')
);
const contentSection = document.getElementById('contentSection');
if (contentSection.hasChildNodes()) {
contentSection.replaceChild(table,contentSection.firstElementChild);
} else {
contentSection.appendChild(table);
}
}
function getRouteImage(route) {
const img = document.createElement('img');
img.src = 'https://www.swu.de/typo3conf/ext/swu_timetables/Resources/Public/Icons/Routes/linie-' + route + '.svg';
img.setAttribute("class","routeImage");
return img;
}
function getTable(listHead, list, listData) {
const table = document.createElement('table');
if (HEADER_ROW) {
const headrow = document.createElement('tr');
table.appendChild(headrow);
for (let fn of listHead) {
const cell = document.createElement('th');
fn(cell);
headrow.appendChild(cell);
}
}
for (let dataPoint of listData) {
const row = document.createElement('tr');
for (let fn of list) {
const cell = document.createElement('td');
fn(cell, dataPoint);
row.appendChild(cell);
}
table.appendChild(row);
}
return table;
}
refreshData();
// setInterval(refreshData, 15000);

14
index.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="fetchapi.js"></script>
</head>
<body>
<div id="headerBar">
<span id="stationName"></span>
<span id="timeBox">--:--</span>
</div>
<div id="contentSection"></div>
</body>
</html>

71
style.css Normal file
View File

@ -0,0 +1,71 @@
* {
padding: 0;
margin: 0;
}
body {
font-family: Helvetica, sans;
width: 50%;
padding: 0;
margin: 0;
}
#headerBar {
font-size: 46px;
font-weight: bold;
color: white;
background-color: #444;
padding: 8px;
}
#stationName, #timeBox {
}
#timeBox {
float: right;
}
#contentSection {
width: 100%;
}
#contentSection table {
width: 100%;
}
#contentSection .routeImage {
width: 100%;
}
#contentSection tr:nth-child(even) {
background-color: #EEE;
}
#contentSection th {
font-size: 26px;
text-align: left;
padding: 8px;
}
#contentSection td {
font-size: 28px;
padding-left: 12px;
padding-right: 4px;
padding-top: 8px;
}
.cellRoute {
width: 45px;
height: 45px;
}
.cellDest {
font-size: 36px;
}
.cellTime {
font-size: 50px;
font-weight: bold;
text-align: right;
margin-right: 20px;
}