-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
203 lines (166 loc) · 5.62 KB
/
script.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**
* Smartmirror
* ---
* @author Michael Pomogajko
* @version 0.1
* ---
* Note: Read the README!
* ---
*/
var months = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"];
var days = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"];
var errrorCount = 0;
function getStations(data) {
try {
var buff = [];
var str = data.substring(data.indexOf("<div class=\"col-sm12\""), data.indexOf("<div class=\"row\">"));
$(str).find('td').each(function() {
buff.push(this.innerText)
});
buff.splice(0,4);
var deps = [];
for (var i = 0; i < 30; i++) {
if (i % 3 === 0) {
var dep = {};
dep.line = buff[i];
dep.to = buff[i + 1];
dep.time = buff[i + 2];
deps.push(dep);
}
}
fillStations(deps);
$('#notif').text("");
} catch (err) {
$('#notif').text("Error");
}
}
function getStationBerlin(data) {
var buff = [];
var deps = []
// var str ="<span "+ data.substring(data.indexOf("stationOverview"), data.indexOf("</table"));
// console.log(str);
$($(data).find('table')[0]).find('td').each(function() {
buff.push(this.innerText.replace(/(\r\n|\n|\r)/gm,""));
});
for (var i = 0; i < 30; i++) {
if (i % 3 === 0) {
var dep = {};
dep.time = buff[i];
dep.line = buff[i + 1];
dep.to = buff[i + 2];
deps.push(dep);
}
}
fillStations(deps);
$('#notif').text("");
}
function fillStations(stations) {
var table = $("#tbody");
table.html("");
var destset = ["Weiden West", "Junkersdorf", "Universität", "Sülz"];
stations.forEach(function (stat) {
if (destset.indexOf(stat.to) != -1) {
table.append("<tr class='highlight'><td>" + stat.line + "</td><td>" + stat.to + "</td><td>" + stat.time + "</td></tr>");
} else {
table.append("<tr><td>" + stat.line + "</td><td>" + stat.to + "</td><td>" + stat.time + "</td></tr>");
}
});
}
function loadClock() {
// Format: Samstag, 21. Januar 2017
var displayDate = $('#date');
var displayClock = $('#clock');
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth();
var weekday = date.getDay();
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
hours < 10 ? hours = "0" + hours : null;
minutes < 10 ? minutes = "0" + minutes : null;
displayDate.text(days[weekday] + ", " + day + ". " + months[month] + " " + year);
displayClock.text(hours + ":" + minutes);
}
function loadDepartures() {
$.ajax({
url: "http://www.kvb-koeln.de/qr/" + params.depID,
type: 'GET',
success: function (res) {
// console.log(res);
getStations(res);
$('#header').text("Abfahrten von Fuldaerstr.");
// console.log("succes");
errrorCount = 0;
},
error: function (err) {
console.log("Error");
// console.log(err);
$('#header').text("Error #" + errrorCount++);
}
});
}
function loadDeparturesBerlin() {
// console.log("loading depts");
var link = "https://fahrinfo.bvg.de/Fahrinfo/bin/stboard.bin/dn?boardType=depRT&application=FILTER&view=STATIONINFO&maxJourneys=20&REQProduct_5_name=yes&REQProduct_6_name=yes&REQProduct_0_name=yes&REQProduct_1_name=yes&REQProduct_2_name=yes&REQProduct_3_name=yes&REQProduct_4_name=yes&input=+S+Hackescher+Markt+%28Berlin%29&REQ0JourneyStopsSID=A%3D1%40O%3DS+Hackescher+Markt+%28Berlin%29%40X%3D13402359%40Y%3D52522605%40U%3D86%40L%3D900100002%40B%3D1%40p%3D1512043087%40&REQ0JourneyProduct_prod_list_6=0000001000000000&REQ0JourneyProduct_prod_list_0=1000000000000000&REQ0JourneyProduct_prod_list_1=0100000000000000&REQ0JourneyProduct_prod_list_2=0010000000000000&REQ0JourneyProduct_prod_list_3=0001000000000000&REQ0JourneyProduct_prod_list_4=0000100000000000&existBikeEverywhere=yes&selectDate=today×electEnd=Zurücksetzen&start="
$.ajax({
url: link,
type: 'GET',
success: function (res) {
console.log("success");
getStationBerlin(res);
},
error: function (err) {
console.log("Error");
console.log(err);
}
});
}
function loadWeather() {
var weather = $('#weather').weatherWidget({
cacheTime: 1,
lat: 50.941357,
lon: 6.958307,
key: params.forecastApi,
celsius: true,
imgPath: "./weather/img/"
});
}
function loadCalendar() {
var calendar = $('#calendar').fullCalendar({
googleCalendarApiKey: params.calendarApi,
locale: "de",
timeFormat: "HH:mm",
height: 620,
eventColor: '#494949',
weekNumbers: true,
eventSources: [
{
googleCalendarId: params.calendarIDs[0]
},
{
googleCalendarId: params.calendarIDs[1]
}
]
});
}
$(function () {
loadClock();
loadWeather();
loadCalendar();
loadDepartures();
// loadDeparturesBerlin();
setInterval(function () {
$('#calendar').fullCalendar('refetchEvents');
}, 1000 * 60 * 60);
setInterval(function () {
$('#weather').html("");
loadWeather();
}, 1000 * 60 * 30);
setInterval(function () {
loadDepartures();
}, 1000 * 15);
setInterval(function () {
loadClock();
}, 1000 * 10);
});