forked from opendatacity/re-data
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scraper.js
1541 lines (1269 loc) · 42.5 KB
/
scraper.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* get node modules */
var fs = require('fs');
var path = require('path');
var eventId = "34c3";
/* get npm modules */
var scrapyard = require('scrapyard');
var http = require('http');
var moment = require('moment');
var ent = require('ent');
var cheerio = require('cheerio');
var sanitizeHtml = require('sanitize-html');
var parseCSV = require('csv-parse');
var async = require('async');
var md5 = require('MD5');
var ical = require('ical');
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var icalendar = require('icalendar');
var log = require(path.resolve(__dirname, '../../api/lib/log.js'));
var json_requester = require('../lib/json_requester');
var additional_schedule_url = "http://data.conference.bits.io/data/34c3/voc/workshops.schedule.json";
// var dlf_schedule_url = "http://data.c3voc.de/34C3/workshops.schedule.json";
var freifunk_schedule_url = "https://frab.txtfile.eu/en/34c3-ffc/public/schedule.json";
var freifunk_speaker_url = "https://frab.txtfile.eu/en/34c3-ffc/public/speakers.json";
var schedule_url = "https://fahrplan.events.ccc.de/congress/2017/Fahrplan/schedule.json";//"http://data.conference.bits.io/data/32c3/schedule.json"; //
var speakers_url = "https://fahrplan.events.ccc.de/congress/2017/Fahrplan/speakers.json"; // "http://data.conference.bits.io/data/32c3/speakers-frap.json"; //
var halfnarp_url = "http://halfnarp.events.ccc.de/-/talkpreferences";
var voc_streams_api_url = "https://streaming.media.ccc.de/streams/v1.json";
var poi_titles_url = "https://github.com/NoMoKeTo/c3nav/raw/master/src/projects/34c3/titles.json";
// var pois = "https://raw.githubusercontent.com/NoMoKeTo/c3nav/master/src/projects/34c3/pois.json";
var poi_graph_url = "https://raw.githubusercontent.com/NoMoKeTo/c3nav/master/src/projects/34c3/graph.json";
// CSV data
var lounge_session_csv_data = fs.readFileSync(__dirname + "/party_lounge.csv");
var chill_out_lounge_csv_data = fs.readFileSync(__dirname + "/34c3_4Floor_ChillOut_LineUp.csv");
var dome_lounge_csv_data = fs.readFileSync(__dirname + "/dome.csv");
//"https://gist.githubusercontent.com/MaZderMind/d5737ab867ade7888cb4/raw/bb02a27ca758e1ca3de96b1bf3f811541436ab9d/streams-v1.json"
// later at https://streaming.media.ccc.de/streams/v1.json
// for debugging we can just pretend rp14 was today
var originalStartDate = new Date(Date.UTC(2015, 11, 27, 10, 0, 0, 0));
var fakeDate = originalStartDate; // new Date(Date.UTC(2015, 11, 23, 16, 0, 0, 0));
var sessionStartDateOffsetMilliSecs = fakeDate.getTime() - originalStartDate.getTime();
var dayYearChange = 0;
var dayMonthChange = 0;
var dayDayChange = 0;
// console.log("Real date: " + originalStartDate);
// console.log("Fake date: " + fakeDate);
// http://hls.stream.c3voc.de/hls/sN_L_Q.m3u8
// N ∈ [1;5], L ∈ {native, translated}, Q ∈ {hd, sd, slides}.
var sortOrderOfLocations = [
'34c3-saal-adams',
'34c3-saal-borg',
'34c3-saal-g',
'34c3-saal-clarke',
'34c3-saal-dijkstra',
mkID("Lecture room 11"),
mkID("Seminar room 14-15"),
mkID("Lecture room 12"),
mkID("Seminar room 13"),
mkID("CCL Hall 3"),
mkID("Chaos West Stage"),
mkID("Hive Stage"),
mkID("Komona Aquarius"),
mkID("Komona Coral Reef"),
mkID("Komona D.Ressrosa"),
mkID("Komona Blue Princess"),
mkID("Kidspace")
];
// to map VOC API output to our rooms
var vocSlugToLocatonID = {
"Saal Adams": mkID("saal-adams"),
"Saal Borg": mkID("saal-borg"),
"Saal Clarke": mkID("saal-clarke"),
"Saal Dijkstra": mkID("saal-dijkstra")
};
var locationNameChanges = {
//"34c3-sendezentrumsb-hne": "Sendezentrum",
//"34c3-podcastingtisch": "Podcasttisch"
};
var poi2locationMapping = {
//"34c3-h1": mkID("saal-1")
};
var additionalLocations = [
];
var additionalLinks = {
};
var additionalEnclosures = {
"34c3-workshop-e7d29e30-123b-4840-a2fc-e6674ad6c455": {
"url": "https://ccc.cdn.as250.net/34c3/Markus_Drenger_beA.mp4",
"mimetype": "video/mp4",
"type": "recording",
"thumbnail": "https://img.youtube.com/vi/Od5WAah-ktk/hqdefault.jpg"
}
};
var additionalPOIs = [
{
"label_de": "Sendezentrum",
"label_en": "Sendezentrum",
"id": mkID("poi-sendezentrum"),
"category": "session-location",
"location": {
"id": "34c3-b-hne",
"label_de": "Sendezentrum",
"label_en": "Sendezentrum"
},
"hidden": false,
"positions": [
{"map": "34c3-map-level1",
"x": 2969.47265625,
"y": 1690.3660714285713}
],
"links": [],
"priority": 100,
"type": "poi"
}
];
// Livestream test
var streamURLs = {
// "camp15-saal-1": "http://hls.stream.c3voc.de/hls/s1_native_hd.m3u8",
};
var testVideoURLs = {
// "34c3-7415": "http://cdn.media.ccc.de/congress/2014/h264-hd/31c3-6582-de-Das_Transparenzportal_Hamburg_hd.mp4" // Talk:Wie Jugendschutzprogramme nicht nur die Jugend schädigen Video: Das Transparenzportal Hamburg
};
// Security #5057af blue
// Politics #b550bd violett
// Science #45b9b3 turqise
// Hardware #a8563f brown
// Art #b99745 orange
// Failosophy #c0ba59 yellow
// CCC #45b964 green
// Entertainment #45b964 (same as CCC) green
//
// official from https://events.ccc.de/congress/2017/wiki/Static:Design
var blue = [ 80.0, 87.0, 175.0, 1.0];
var violett = [181.0, 80.0, 189.0, 1.0];
var turquise= [ 69.0, 185.0, 179.0, 1.0];
var brown = [168.0, 86.0, 63.0, 1.0];
var orange = [185.0, 151.0, 69.0, 1.0];
var yellow = [192.0, 186.0, 89.0, 1.0];
var green = [ 69.0, 185.0, 100.0, 1.0];
// non-official
var red = [118.0, 26.0, 61.0, 1.0];
var grey = [110.0, 110.0, 110.0, 1.0];
var black = [ 0.0, 0.0, 0.0, 1.0];
var cream = [135.0, 81.0, 86.0, 1.0];
var colors = {};
colors[eventId + "-security"] = blue;
colors[eventId + "-ethics-society-politics"] = violett;
colors[eventId + "-science"] = turquise;
colors[eventId + "-hardware-making"] = brown;
colors[eventId + "-art-culture"] = orange;
colors[eventId + "-failosophy"] = yellow;
colors[eventId + "-ccc"] = green;
colors[eventId + "-entertainment"] = green;
colors[eventId + "-self-organized-sessions"] = grey;
colors[eventId + "-podcast"] = red;
colors[eventId + "-sendezentrum"] = red;
colors[eventId + "-other"] = grey;
var allFormats = {
'discussion': { id:'discussion', label_en:'Discussion' },
'talk': { id:'talk', label_en:'Talk' },
'workshop': { id:'workshop', label_en:'Workshop' }
}
var allLevels = {
'beginner': { id:'beginner', label_en:'Beginner' },
'intermediate': { id:'intermediate', label_en:'Intermediate' },
'advanced': { id:'advanced', label_en:'Advanced' }
};
var allLanguages = {
'en': { id:'en', label_en:'English' },
'de': { id:'de', label_en:'German' },
};
var allMaps = {
};
var allPOIs = {};
var data = [];
var allDays = {
};
var allRooms = {};
var allSpeakers = {};
var allTracks = {};
var allSpeakers = {};
var allRecommendations = {};
function addEntry(type, obj) {
obj.event = eventId;
obj.type = type;
data.push(obj);
}
function alsoAdd(type, list) {
Object.keys(list).forEach(function (key) {
var obj = clone(list[key]);
obj.event = eventId;
obj.type = type;
data.push(obj);
})
}
function mkID(string) {
return eventId + "-" + string.toString().replace(/[^A-Za-z0-9]+/g, '-').toLowerCase();
}
function mkID(string, prefix) {
if (prefix == undefined) return eventId + "-" + string.toString().replace(/[^A-Za-z0-9]+/g, '-').toLowerCase();
return eventId + "-" + prefix + "-" + string.toString().replace(/[^A-Za-z0-9]+/g, '-').toLowerCase();
}
// HALFNARP - Recomendations
function recommendedSessions(halfnarp, frapSessions) {
let validSessionIds = [];
for (day of frapSessions.schedule.conference.days) {
for (roomName in day.rooms) {
let sessions = day.rooms[roomName];
let ids = sessions.map((session) => session.id);
validSessionIds = validSessionIds.concat(ids);
}
}
// Store all classified sessions for each
let result = {};
let sessions = halfnarp;
for (session of sessions) {
let sessionId = mkID(`${session.event_id}`);
let recommedations = [];
for (otherSession of sessions) {
if (session.event_id === otherSession.event_id ||
validSessionIds.indexOf(otherSession.event_id) === -1) {
continue;
}
let distance = halfnarpEventDistance(session, otherSession);
if (distance) {
recommedations.push({"title": otherSession.title,
"id": mkID(`${otherSession.event_id}`),
"distance": distance});
}
}
recommedations = recommedations.sort((a,b) => {
return a.distance - b.distance;
}).filter((a) => a.distance < 100).map((a) => {
return {"title": a.title,
"id": a.id}
});
result[sessionId] = recommedations.slice(0,5);
}
return result;
}
function halfnarpEventDistance(sessionA, sessionB) {
let distance = 0;
let aClassifiers = Object.keys(sessionA.event_classifiers);
if (aClassifiers.length == 0) {
console.log(sessionA);
return null;
}
for (classifier in sessionA.event_classifiers) {
let aWeight = sessionA.event_classifiers[classifier];
let bWeight = sessionB[classifier];
if (!bWeight) bWeight = -10;
distance = distance + Math.abs(aWeight - bWeight);
}
for (classfier in sessionB.event_classifiers) {
if (aClassifiers.indexOf(classifier)) {
continue;
}
distance = distance + sessionB.event_classifiers[classifier] + 5;
}
if (sessionA.track_id === sessionB.track_id) {
distance = distance * 0.95;
}
let numberOfClassifiers = Object.keys(sessionA.event_classifiers).length
return distance / numberOfClassifiers;
}
function parseDay(dayXML) {
var date = dayXML.date;
// console.log("parsing: ", dayXML);
var comps = date.split("-");
var parseDate = new Date(date);
parseDate.setUTCFullYear(parseDate.getUTCFullYear() + dayYearChange);
parseDate.setUTCMonth(parseDate.getUTCMonth() + dayMonthChange);
parseDate.setUTCDate(parseDate.getUTCDate() + dayDayChange);
var dateLabelDe = date;
var dateLabelEn = date;
var index = 0;
var monthDay = parseDate.getUTCDate();
switch (monthDay) {
case 27:
index = 1;
dateLabelDe = "Tag 1";
dateLabelEn = "Day 1";
break;
case 28:
index = 2;
dateLabelDe = "Tag 2";
dateLabelEn = "Day 2";
break;
case 29:
index = 3;
dateLabelDe = "Tag 3";
dateLabelEn = "Day 3";
break;
case 30:
index = 4;
dateLabelDe = "Tag 4";
dateLabelEn = "Day 4";
break;
default:
return null;
}
var id = mkID(index);
var day = {
"id": id,
"event": eventId,
"type": "day",
"label_en": dateLabelEn,
"label_de": dateLabelDe,
"date": date
};
// console.log("DAY ", day);
return day;
}
function parseSpeaker(speakerJSON, imageURLPrefix) {
var bio = "";
if (speakerJSON.abstract) {
bio = speakerJSON.abstract;
}
if (speakerJSON.description) {
bio = bio + "\n\n" + speakerJSON.description;
}
var links = [];
if (speakerJSON.links) {
speakerJSON.links.forEach(function (link) {
var url = link.url
if (url.indexOf("http") != 0) {
url = "http://" + url;
}
links.push({"url": url,
"title": link.title,
"service": "web",
"type": "speaker-link"});
});
}
var result = {
"id": mkID(speakerJSON.full_public_name),
"type": "speaker",
"event": eventId,
"name": speakerJSON.full_public_name,
"biography": bio,
"links": links,
"sessions": [] // fill me later
};
// de-htmlize
// console.log(bio);
// $ = cheerio.load(bio);
result["biography"] = sanitizeHtml(bio, {allowedTags: []});
// sys.puts(sys.inspect(handler.dom, false, null));
var imageHost = imageURLPrefix;
if (speakerJSON.photo) {
result['photo'] = speakerJSON.photo;
}
if (speakerJSON.image) {
var path = speakerJSON.image;
path = path.replace(/\/medium\//,'/large/');
result['photo'] = imageHost + path;
}
return result;
};
function parseRoom(roomName, index, namePrefix) {
var roomName = roomName;
if (namePrefix != null) {
roomName = namePrefix + roomName;
}
var id = mkID(roomName);
// change some names
var newName = locationNameChanges[id];
if (newName) {
roomName = newName;
}
return {
"id": id,
"label_en": roomName,
"label_de": roomName,
"is_stage": roomName.toString().match(/Stage/i) ? true : false,
"floor": 0,
"order_index": index,
"event": eventId,
"type": "location"
};
};
function generateIcalData(allSessions) {
var ical = new icalendar.iCalendar();
allSessions.forEach(function (session) {
var event = new icalendar.VEvent(session.id);
event["TZID"] = "Europe/Berlin";
var summary = session.title;
if (session.subtitle) {
summary = summary + " – " + session.subtitle
}
event.setSummary(summary);
var description = "";
if (session.abstract && session.description) {
description = session.abstract + "\n\n" + session.description;
} else if (session.abstract) {
description = session.abstract;
} else if (session.description) {
description = session.description;
}
event.setDescription(description);
if (session.location) {
event.setLocation(session.location.label_en);
}
event.setDate(session.begin, session.end);
ical.addComponent(event);
});
var filepath = __dirname + "/../../web/data/" + eventId + "/sessions.ics";
filepath = path.normalize(filepath);
fs.writeFile(filepath, ical.toString(), function (err) {
});
};
function parseDate(dateString) {
var date = new Date(dateString);
var newMillis = date.getTime() + sessionStartDateOffsetMilliSecs;
date.setTime(newMillis);
return date;
};
function parseEnd(dateString, durationString) {
var dayChange = 4
var eventDate = new Date(dateString);
var time = eventDate.getTime() / 1000;
var match = durationString.toString().match(/(\d?\d):(\d\d)/);
var hours = new Number(match[1]);
var minutes = new Number(match[2]);
var seconds = time + (minutes * 60.0) + (hours * 60.0 * 60.0);
var date = new Date(seconds * 1000);
var newMillis = date.getTime() + sessionStartDateOffsetMilliSecs;
date.setTime(newMillis);
if (date.getTime() <= eventDate.getTime()) {
date.setTime(eventDate.getTime() + (1000 * 3600));
}
// if the event starts on day 1 but ends on day 2 after day change,
// cap it to day change
if (eventDate.getUTCDate() < date.getUTCDate() &&
date.getUTCHours() > dayChange )
{
date.setUTCHours(dayChange - 1);
date.setUTCDate(eventDate.getUTCDate() + 1);
}
// if the event starts before day change but ends after, normalize it's end
// to day change
if (eventDate.getUTCHours() <= dayChange && date.getUTCHours() > dayChange) {
date.setUTCHours(dayChange - 1);
}
return date;
}
function parseTrackFromEvent(eventXML, defaultTrack) {
var trackName = eventXML.track;
// if no track name is given we just return the default
if (trackName == null) {
return defaultTrack;
}
// console.log(trackName);
var id = mkID(trackName);
var color = colors[id];
if (!color) {
color = [109.0, 109.0, 109.0, 1.0]; // grey by default
}
return {
"id": id,
"color": color,
"label_en": trackName.toString(),
"label_de": trackName.toString()
};
};
function normalizeXMLDayDateKey(date, begin) {
var parseDate = new Date(date);
parseDate.setUTCFullYear(parseDate.getUTCFullYear() + dayYearChange);
parseDate.setUTCMonth(parseDate.getUTCMonth() + dayMonthChange);
parseDate.setUTCDate(parseDate.getUTCDate() + dayDayChange);
// if this is for a session we sanatize the date in case of strange input
if (begin) {
// if (begin.getUTCDate() != parseDate.getUTCDate() ||
// begin.getUTCMonth() != parseDate.getUTCMonth() ||
// begin.getUTCDate() != parseDate.getUTCDate())
// {
// TODO: get day begin as input
if (begin.getHours() >= 9) {
// this is ok only if the session is very early, so we return the date from begin
var realBegin = "" + begin.getUTCFullYear() + "-" + (begin.getUTCMonth() + 1) + "-" + begin.getUTCDate();
// log.warn("Given 'day' date and 'begin' date of the session don't match and this is not an early morning session! date says:", parseDate, " vs begin:", begin, " returning ", realBegin);
return realBegin;
} else if (begin.getHours() >= 5) {
// this is ok only if the session is very early, so we return the date from begin
var realBegin = "" + begin.getUTCFullYear() + "-" + (begin.getUTCMonth() + 1) + "-" + (begin.getUTCDate() - 1);
log.warn("Session is to early, returning ", realBegin, " as begin date instead of ", parseDate, " begin: ", begin);
return realBegin;
}
// }
}
// console.log("normalized " + date );
date = "" + parseDate.getUTCFullYear() + "-" + (parseDate.getUTCMonth() + 1) + "-" + parseDate.getUTCDate();
// console.log("to " + date );
return date;
}
function parseEvent(event, day, room, locationNamePrefix, trackJSON, streamMap, idPrefix, linkMakerFunction, idField) {
var links = [];
if (idField == null) {
idField = "id"
}
var id = mkID(event[idField]);
if (typeof(idPrefix) == "string") {
id = mkID(event[idField], idPrefix);
}
var linkFunction = linkMakerFunction;
if (linkFunction == null) {
linkFunction = function (session, sourceJSON) {
if (!event[idField]) return "https://fahrplan.events.ccc.de/congress/2017/Fahrplan/";
return "https://fahrplan.events.ccc.de/congress/2017/Fahrplan/events/" + event[idField] + ".html";
};
}
event.links.forEach(function (link) {
var url = null;
var title = null;
if (typeof(link) === "string") {
url = link;
title = link;
} else if (typeof(link) === "object" && link["title"] && link["url"]) {
title = link["title"];
url = link["url"];
}
if (typeof(url) == "string" && url.indexOf("//") == 0) {
url = "http:" + url;
}
if (typeof(url) == "string" && !(url.indexOf("http://") == 0) && !(url.indexOf("https://") == 0)) {
url = "http://" + url;
}
links.push({
"title": title,
"url": url,
"type": "session-link"
});
});
let link = additionalLinks[id];
if (link) {
links.push(link);
}
var begin = parseDate(event.date);
// Make sure day change is at 5 in the morning
var hourOffset = 1;
var hours = begin.getUTCHours() + hourOffset;
var time = new Date(2017, 11, 27);
if (begin.getTime() < time.getTime()) {
console.log("No valid begin: " + begin);
return null;
}
var dayKey = normalizeXMLDayDateKey(day["date"], begin);
var eventTypeId = event.type.toString();
if (eventTypeId == 'lecture') {
eventTypeId = 'talk';
} else if (eventTypeId == 'other') {
eventTypeId = 'talk';
} else if (eventTypeId == 'meeting') {
eventTypeId = 'workshop';
}
var day = allDays[dayKey];
if (!day) {
console.log("No valid day for " + event.title.toString() + " " + dayKey);
return null;
}
var track = event.track;
if (track == null) track = "Other";
var locationNameDe = allRooms[room.id]["label_de"];
var locationNameEn = allRooms[room.id]["label_en"];
if (locationNamePrefix != null) {
locationNameDe = locationNamePrefix + locationNameDe;
locationNameEn = locationNamePrefix + locationNameEn;
}
if (event.id.toString() == "1103") {
console.log("Event: ", event);
}
var session = {
"id": id, // Do not use GUID so we keep in line with Halfnarp IDs
"title": event.title.toString(),
"abstract": sanitizeHtml(event.abstract.toString(), {allowedTags: []}),
"description": sanitizeHtml(event.description.toString(), {allowedTags: []}),
"begin": begin,
"end": parseEnd(event.date, event.duration),
"track": {"id": trackJSON.id, "label_de": trackJSON.label_de, "label_en": trackJSON.label_en},
"day": day,
"format": allFormats[eventTypeId],
"level": allLevels['advanced'],
"lang": allLanguages[event.language.toString() != null ? event.language.toString() : 'en'],
"speakers": [], // fill me later
"enclosures": [], // fill me later
"links": links
};
let recommendations = allRecommendations[id];
if (!recommendations) recommendations = [];
session["related_sessions"] = recommendations;
if (session.title.match(/\bcancelled\b/i) || session.title.match(/\babgesagt\b/i)) {
session["cancelled"] = true;
} else {
session["cancelled"] = false;
}
if (allRooms[room.id] != undefined && allRooms[room.id]["id"] != mkID("")) {
session["location"] = {
"id": allRooms[room.id]["id"],
"label_de": allRooms[room.id]["label_de"],
"label_en": allRooms[room.id]["label_en"]
};
var recordingLocationIds= [];
var locationId = session["location"]["id"];
var willBeRecorded = undefined;
if (event["do_not_record"] == true) {
willBeRecorded = false;
} else if (toArray(vocSlugToLocatonID).indexOf(locationId) != -1) {
willBeRecorded = true;
}
session["will_be_recorded"] = willBeRecorded;
}
if (!session.format) {
log.warn("Session " + session.id + " (" + session.title + ") has no format")
session["format"] = allFormats['talk'];
}
if (!session.lang){
session.lang = allLanguages['en'];
}
if (event.subtitle.toString() != "") {
session["subtitle"] = event.subtitle.toString();
}
// HACK: Fake one video for App Review
var testVideoURL = testVideoURLs[session.id];
if (testVideoURL) {
session.enclosures.push({
"url": testVideoURL,
"mimetype": "video/mp4",
"type": "recording",
"thumbnail": "http://static.media.ccc.de/media/congress/2013/5490-h264-iprod_preview.jpg"
});
}
let additionalEnclosure = additionalEnclosures[session.id];
if (additionalEnclosure) {
session.enclosures.push(additionalEnclosure);
}
if (session.location) {
var stream = streamMap[session.location.id];
if (stream) {
session.enclosures.push(stream);
}
}
if (session.location) {
var streamURL = streamURLs[session.location.id];
if (streamURL) {
session.enclosures.push({
"url": streamURL,
"mimetype": "video/mp4",
"type": "livestream"
});
}
}
session.url = linkFunction(session, event);
return session;
};
function handleResult(events, speakers, eventRecordings, locationNamePrefix, defaultTrack, speakerImageURLPrefix, streamMap, idPrefix, linkMakerFunction, idField) {
if (!speakers) {
speakers = [];
}
speakers.forEach(function (speaker) {
var speakerJSON = parseSpeaker(speaker, speakerImageURLPrefix);
if (allSpeakers[speakerJSON.id]) {
var speaker = allSpeakers[speakerJSON.id];
// ["links", "sessions"].forEach(function(item){
// // concat + uniq
// var concated = speaker[item].concat(speakerJSON[item]);
//
// speakerJSON[item] = concated.filter(function(elem, pos) {
// return concated.indexOf(elem) == pos;
// });
// });
["biography", "photo"].forEach(function (item) {
// if the old thing has be
if (speaker[item] && speakerJSON[item] && speaker[item].length > speakerJSON[item].length) {
speakerJSON[item] = speaker[item];
} else {
speaker[item] = speakerJSON[item];
}
});
// var result = {
// "id": mkID(speakerJSON.full_public_name),
// "type": "speaker",
// "event": eventId,
// "name": speakerJSON.full_public_name,
// "biography": bio,
// "links": links,
// "sessions": [] // fill me later
// };
}
allSpeakers[speakerJSON.id] = speakerJSON;
});
events.schedule.conference.days.forEach(function(day) {
// Day
// ---
var dayJSON = parseDay(day);
if (dayJSON) {
var key = normalizeXMLDayDateKey(dayJSON.date);
allDays[key] = dayJSON;
}
});
events.schedule.conference.days.forEach(function(day) {
var roomIndex = 0;
var rooms = day.rooms;
Object.keys(rooms).forEach(function (roomLabel) {
// Room
// ----
var roomJSON = parseRoom(roomLabel, roomIndex, locationNamePrefix);
allRooms[roomJSON.id] = roomJSON;
roomIndex++;
additionalLocations.forEach(function (locationJSON) {
allRooms[locationJSON.id] = locationJSON;
});
var events = rooms[roomLabel];
events.forEach(function (event) {
// Track
// -----
var trackJSON = parseTrackFromEvent(event, defaultTrack);
if (parseTrackFromEvent.id == trackJSON.id) {
console.log("!!!! DEFAULT TRACK FOR ", event.title);
}
allTracks[trackJSON.id] = trackJSON;
// Event
// -----
var eventJSON = parseEvent(event, day, roomJSON, locationNamePrefix, trackJSON, streamMap, idPrefix, linkMakerFunction, idField);
// if event could not be parse skip it
if (eventJSON == null) return;
// Event Speakers
// --------------
event.persons.forEach(function (person) {
var publicName = person["public_name"];
if (publicName == undefined) return;
var personID = mkID(publicName);
var speaker = allSpeakers[personID];
if (speaker) {
speaker.sessions.push({
"id": eventJSON.id,
"title": eventJSON.title
});
var person = {"id": personID,
"name": speaker.name};
eventJSON.speakers.push(person);
}
});
// Videos
// ------
var recordingJSON = null;
eventRecordings.forEach(function (element) {
if (eventJSON && element && eventJSON.title == element.title) {
recordingJSON = element;
}
});
if (recordingJSON && recordingJSON.recording) {
eventJSON.enclosures.push({
"url": recordingJSON.recording.recording_url,
"mimetype": "video/mp4",
"type": "recording",
"thumbnail": recordingJSON.thumb
});
}
if (eventJSON != null) {
addEntry('session', eventJSON);
}
});
});
});
}
function handlePOIs(graph, titles) {
var POIs = {}
var map2level = {0: "map-level0",
1: "map-level1",
2: "map-level2",
3: "map-level3",
4: "map-level4"};
var poisForMaps = {};
for (roomID in graph.rooms) {
var roomShape = graph.rooms[roomID];
var roomTitles = titles[roomID];
var mapID = map2level[roomShape.level];
var pois = poisForMaps[mapID];
if (!pois) pois = [];
var poi = poiForRoomShape(roomID, roomShape, roomTitles, mapID);
if (!poi) continue;
pois.push(poi);
poisForMaps[mapID] = pois;
}
var allPois = [];
additionalPOIs.forEach(function (poi) {
allPois.push(poi);
});
for (mapID in poisForMaps) {
var map = allMaps[mapID];
if (!map) continue;
var pois = poisForMaps[mapID];
pois.forEach(function (poi) {
var mapPOIs = map.pois;
if (!mapPOIs) mapPOIs = [];
mapPOIs.push(poi);
map.pois = mapPOIs;
allPois.push(poi);
});
}
alsoAdd("poi", allPois);
}
function handleCSVResult(csvData, defaultTrack, shareURL, locationIdentifier, callback) {
callback(null, []);
return;
parseCSV(csvData, {"delimiter": ";",
"auto_parse": false,
"auto_parse_date": false,
"columns": true,
"skip_empty_lines": true}, function(err, output) {
var sessions = [];
if (err) {
log.error("CSV Parse Error: ", err);
} else {
// console.log(output);
var index = 0;
output.forEach(function (row) {
if (!row.tag || !row.beginn || !row.ende || row.tag.length == 0 ) {
return;
};
var components = row.tag.split(".");
if (components.length != 3) { console.error("Could not parse date from CSV: ", row.tag); return; };
var day = components[0];
var month = components[1];