-
Notifications
You must be signed in to change notification settings - Fork 6
/
gf-od.php
533 lines (445 loc) · 13.8 KB
/
gf-od.php
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
<?php
// This converts the events from the open data website of Gent for use in the
// Android application.
// https://datatank.stad.gent/4/toerisme/gentsefeestenevents.json
// https://datatank.stad.gent/4/cultuursportvrijetijd/gentsefeestenlocaties.json
// https://datatank.stad.gent/4/toerisme/gentsefeestencategorien.json
// Download the events file locally in a file called 'events.json'.
// You can ignore the other files, their data is small and defined in the
// arrays in the app.
// Get content.
if (!file_exists('events.json')) {
print "'events.json' file not found.\n";
exit;
}
$json = file_get_contents('events.json');
// Event uuids - ids.
if (file_exists('uuid_events.json')) {
$uuid_events = unserialize(file_get_contents('uuid_events.json'));
}
else {
$uuid_events = array();
}
$locations_sum = array();
$locations_decoded = json_decode(file_get_contents('gentsefeestenlocaties.json'));
//print_r($locations_decoded);
//return;
$locations = array();
$i = 1;
foreach ($locations_decoded as $location) {
$location = (array) $location;
//print_r($location);
//return;
$id = $location['fields']->id;
$locations[$id] = $location;
$locations[$id]['locatie_id'] = $i;
$name = $location['fields']->name_nl;
$l_set = FALSE;
$locations_sum[] = array(
'id' => $i,
'name' => $name,
);
if (strpos($name, 'Baafs') !== FALSE || strpos($name, 'Brewery') !== FALSE || strpos($name, 'Stage') !== FALSE) {
//print $name . ' - ' . $i . "\n";
}
// Salsabar, tref.club -> baudelo
//if ($i == 8 || $i == 6 || $i == 5 || $i == 88 || $i == 351 || $i == 383) {
if ($i == 776 || $i == 1233 || $i == 415 || $i == 1232 || $i == 1234 || $i == 903) {
$locations[$id]['locatie_id'] = 7;
$l_set = TRUE;
}
// Sint jacobs
if (strpos($name, 'Sint-Jacobs') !== FALSE || strpos($name, 'Walter De Buckplein') !== FALSE) {
$locations[$id]['locatie_id'] = 4;
$l_set = TRUE;
}
// Luisterplein
if ($i == 609 || $i == 392) {
$locations[$id]['locatie_id'] = 14;
$l_set = TRUE;
}
// Kinky
if (strpos($name, 'Kinky') !== FALSE || strpos($name, 'Charlatan') !== FALSE || $i == 938) {
$locations[$id]['locatie_id'] = 15;
$l_set = TRUE;
}
// Special
if ($i == 397 || $i == 416 || $i == 417 || $i == 895 || $i == 1087 || $i == 1132) {
$locations[$id]['locatie_id'] = 22;
$l_set = TRUE;
}
// Kouter
if ($i == 889 || $i == 891 || $i == 1174 || $i == 1204 || $i == 47 || $i == 13 || $i == 939 || $i == 1214) {
$locations[$id]['locatie_id'] = 16;
$l_set = TRUE;
}
// Korenmarkt
if ($i == 608) {
$locations[$id]['locatie_id'] = 3;
$l_set = TRUE;
}
// Korenlei-Gralei
if ($i == 423) {
$locations[$id]['locatie_id'] = 10;
$l_set = TRUE;
}
// Groentenmarkt
if ($i == 42 || $i == 115) {
$locations[$id]['locatie_id'] = 12;
$l_set = TRUE;
}
// Emile
if ($i == 610 || $i == 837) {
$locations[$id]['locatie_id'] = 18;
$l_set = TRUE;
}
// Sint-baafs
if ($i == 607) {
$locations[$id]['locatie_id'] = 2;
$l_set = TRUE;
}
// Beverhout
if ($i == 43) {
$locations[$id]['locatie_id'] = 17;
$l_set = TRUE;
}
// Willem
if ($i == 611) {
$locations[$id]['locatie_id'] = 19;
$l_set = TRUE;
}
// Veerle
if ($i == 937 || $i == 726) {
$locations[$id]['locatie_id'] = 13;
$l_set = TRUE;
}
if (!$l_set) {
$locations[$id]['locatie_id'] = 10000;
}
$i++;
}
$cats = array();
$cats_small = array();
$cats_decoded = json_decode(file_get_contents('gentsefeestencategorien.json'));
$ii = 1;
foreach ($cats_decoded as $caty) {
$caty = $caty->fields;
//print_r($caty);
$cats[$caty->id] = $caty;
$cats[$caty->id]->categorie_id = $ii;
$cats_small[$ii] = $caty->name;
$ii++;
}
//print_r($cats_small);
file_put_contents('catssum', print_r($cats, 1));
//die();
//print_r($locations);
//print_r($locations_sum);
file_put_contents('locationssum', print_r($locations_sum, 1));
//die();
// Debugging
$debug = isset($argv[1]) ? TRUE : FALSE;
// Decode.
$decode = json_decode($json);
// Create sql queries.
$statements = "";
//print_r($decode);
//die();
$total_events = 0;
$number = 0;
$double = 0;
$lines = array();
$unique_dates = array();
$location_ids_unique = array();
$names = array();
$doubles = array();
foreach ($decode as $key => $jevent) {
$new_event = $jevent->fields;
if (empty($new_event->startdate)) {
//print "Empty start date: " . $new_event->name_nl . "\n";
continue;
}
//if ($new_event->name_nl == 'EXIT - Circumstances') {
// continue;
//}
//print_r($new_event);
//die();
// The scheme is different, convert it.
$event = new stdClass();
$full_unix = strtotime($new_event->startdate);
$unix_day = strtotime(date('d-m-Y', $full_unix));
//$full_unix += 7200;
$startuur = date('G:i', $full_unix);
$einduur = '';
if (!empty($new_event->enddate)) {
$end_full_unix = strtotime($new_event->enddate);
//$end_full_unix += 7200;
$einduur = date('G:i', $end_full_unix);
}
// 'all day' is einduur 5:59 and startuur not on 6:00
if ($einduur == '5:59' && $startuur == '6:00') {
$startuur = '';
$einduur = '';
}
if ($einduur == '5:59' && $startuur != '6:00') {
$einduur = date('G:i', $full_unix);
}
// Switch date one day back.
$hour = date('G', $full_unix);
$sorting = $full_unix;
if ($hour >= 0 && $hour < 6) {
$full_unix -= 86400;
$unix_day = strtotime(date('d-m-Y', $full_unix));
}
$event->startuur = $startuur;
$event->einduur = $einduur;
$event->tijdstip_sortering = $sorting;
$event->datum = $unix_day;
$event->titel = $new_event->name_nl;
//if (strpos($event->titel, 'Mardi Gras') !== FALSE) {
$n = $event->titel . $event->datum . $event->startuur . $event->einduur;
$doubles[] = $n;
if (isset($names[$n])) {
$double++;
continue;
}
$names[$n] = TRUE;
//}
$desc = isset($new_event->description) ? json_decode($new_event->description) : '';
$event->omschrijving = !empty($desc->nl) ? $desc->nl : '';
$event->url = isset($new_event->url) ? $new_event->url : '';
$event->gratis = isset($new_event->isaccessibleforfree) ? (int) $new_event->isaccessibleforfree : 0;
$location = $new_event->location;
if (isset($locations[$location])) {
//print "location found\n";
//print_r($locations[$location]);
//die();
$event->locatie = $locations[$location]['fields']->name_nl;
$event->locatie_id = $locations[$location]['locatie_id'];
$event->straat = !empty($locations[$location]['fields']->address_streetaddress) ? $locations[$location]['fields']->address_streetaddress : '';
$event->huisnummer = '';
if (!isset($location_ids_unique[$event->locatie_id])) {
$location_ids_unique[$event->locatie_id] = $event->locatie;
}
//print $event->locatie_id . "\n";
}
else {
$event->location = "Anders";
$event->locatie_id = 1000;
$event->straat = '';
print "location not set\n";
}
// Ignore location id 383
if (!empty($event->locatie_id) && $event->locatie_id == 383) {
//print "location id 383\n";
continue;
}
// ID.
$uuid = $new_event->id;
if (isset($uuid_events[$uuid])) {
$id = $uuid_events[$uuid];
}
else {
$id_number = count($uuid_events);
$id_number++;
$id = $id_number;
$uuid_events[$uuid] = $id;
}
$event->id = $id;
//print $event->id . "\n";
// Categories
$event->categorie_naam = '';
$event->categorie_id = 0;
$catje = isset($new_event->theme) ? explode(';', $new_event->theme) : 'nope';
//print_r($new_event);
//print_r($cats);
if (isset($cats[$catje[0]])) {
$event->categorie_naam = $cats[$catje[0]]->name;
$event->categorie_id = $cats[$catje[0]]->categorie_id;
//print $event->categorie_id . " - " . $event->categorie_naam . "\n";
}
// Price
$off = !empty($new_event->offers) ? json_decode($new_event->offers) : '';
//print_r($off)
if (!empty($off[0]->price)) {
$event->prijs = $off[0]->price;
}
else {
$event->prijs = '';
}
//print "price: " . $event->prijs . "\n";
$event->prijs_vvk = '';
// Lat and long are not exported.
$event->latitude = '';
$event->longitude = '';
$event->korting = 0;
$event->festival = 0;
// Image.
$event->afbeelding = '';
/*if (!empty($new_event->image->thumbnailUrl)) {
$event->afbeelding = $new_event->image->thumbnailUrl;
}*/
if ($debug) {
//if (strpos($event->titel, 'Soul Shakers (BE)') !== FALSE) {
//if (strpos($event->titel, 'Ertebrekers') !== FALSE) {
//if (strpos($event->titel, 'Helder') !== FALSE) {
if (strpos($event->titel, 'Ponykamp') !== FALSE) {
//if (strpos($event->titel, 'SHHT') !== FALSE) {
//if (strpos($event->titel, '25e wandelzoektocht Gentse Feesten') !== FALSE) {
//if (strpos($event->titel, 'De fantastische Anna') !== FALSE) {
print_r($new_event);
print_r($event);
print "-------------------------------------------\n";
//print "$full_unix - $unix_day\n";
}
//continue;
}
// The data contains too much info
if ($event->datum < 1657836000 || $event->datum > 1658613600) {
//print "out of range date\n";
continue;
}
//print $new_event->name_nl . ": $unix_day : $startuur - $einduur\n";
// Omschrijving.
// They used html this since 2015, so do some fiddling on it.
$description = $event->omschrijving;
$description = html_entity_decode($description, ENT_QUOTES);
// Replace p and br tags.
$description = str_replace(array('<p>', '<br />', '<br>', '</p>'), array('', "\n", "\n", "\n"), $description);
// Replace
$description = str_replace(' ', ' ', $description);
// Now convert our newlines.
$description = str_replace("\r", "", trim($description));
$description = str_replace("\n", "|NEWLINE|", $description);
$event->omsch = $description;
// Locatie.
$loc = isset($event->locatie) ? trim($event->locatie) : '';
if (!empty($event->straat)) {
$street = trim($event->straat);
if (!empty($event->huisnummer)) {
$street .= " " . $event->huisnummer;
}
$street = trim($street);
if ($street != $loc) {
$loc .= "\n" . $street;
}
}
$loc = str_replace("\r", "", $loc);
$loc = str_replace("\n", "|NEWLINE|", $loc);
$event->locatie = $loc;
// Prijs
if (!empty($event->prijs)) {
$event->prijs = "€ " . $event->prijs;
}
// Keep an array of unique dates.
$udate = $event->datum;
if (!isset($unique_dates[$udate])) {
$unique_dates[$udate] = date('d m Y', $udate);
}
$query = "('" . my_mysql_escape_string($event->titel) . "',";
$query .= "'" . $event->id . "',";
$query .= "'" . $event->gratis . "',";
$query .= "'" . my_mysql_escape_string($event->prijs) . "',";
$query .= "'" . my_mysql_escape_string($event->prijs_vvk) . "',";
$query .= "'" . my_mysql_escape_string($event->omsch) . "',";
//$query .= "'" . ($event->datum + 7200) . "',";
$query .= "'" . ($event->datum) . "',";
$hour_string = "";
if (!empty($event->startuur)) {
$hour_string = $event->startuur;
if (!empty($event->einduur)) {
$hour_string .= ' - ' . $event->einduur;
}
}
$query .= "'" . $hour_string . "',";
$query .= "'" . my_mysql_escape_string($event->startuur) . "',";
// Date sort is broken in so many ways. We thus take the timestamp
// and add the sort which is in the format of hhmm (wihout leading 0)
// for times before 12 and add calculate a sort which we can
// actually use for decent sorting.
$sort = $event->tijdstip_sortering;
$timestamp = 0;
$hours = 0;
if (!empty($sort)) {
//$minutes = substr($sort, -2);
//if (strlen($sort) == 3) {
// $hours = substr($sort, 0, 1);
//echo "$hours - $sort\n";
//}
//else {
// $hours = substr($sort, 0, 2);
//echo "$hours - $sort\n";
//}
// In case hours is after midnight, until 5 in the morning
// add 24 hours more for sorting.
//if ($hours == '00' || $hours < 5) {
// $hours = 24 + $hours;
//}
//$total = ($hours * 3600) + $minutes;
//$timestamp = $event->datum + $total + 7200; // + two hours because datum is in GMT.
$timestamp = $sort;
//echo "$event->datum - $hours - $sort - $total - $timestamp\n";
}
/*if ($event->id == 13235) {
print $timestamp . "\n";
die();
}*/
// Korting is an array or false.
$korting = $event->korting;
if (is_array($korting)) {
$korting = implode(', ', $korting);
}
else {
$korting = '';
}
// Media.
$media = '';
if (!empty($event->afbeelding)) {
$media = $event->afbeelding;
}
//if (!empty($event->videos) && strpos($event->videos->input, 'youtube') !== FALSE) {
// $media['video'] = $event->videos->input;
//}
$query .= "" . $timestamp . ",";
$query .= "'" . my_mysql_escape_string($event->categorie_naam) . "',";
$query .= "'" . $event->categorie_id . "',";
$query .= "'" . my_mysql_escape_string($event->url) . "',";
$query .= "'" . $event->locatie_id . "',";
$query .= "'" . my_mysql_escape_string($event->locatie) . "',";
$query .= "'" . $event->latitude . "',";
$query .= "'" . $event->longitude . "',";
$query .= "'" . my_mysql_escape_string($korting) . "',";
$query .= "'" . $event->festival . "',";
$query .= "'" . $media . "'";
$query .= ")";
if ($event->festival) {
// print $event->titel . "\n";
}
//print_r($event);
$lines[] = $query;
$number++;
$total_events++;
if ($number == 5) {
$number = 0;
$statements .= implode(":SPLIT:", $lines) . "\n";
$lines = array();
}
}
if (!empty($lines)) {
$statements .= implode(",", $lines);
}
function my_mysql_escape_string($string) {
return str_replace("'", "''", $string);
}
//ksort($location_ids_unique);
//print_r($location_ids_unique);
krsort($unique_dates);
print_r($unique_dates);
print "Total events: $total_events - doubles: " . $double . " \n";
//print_r($names);
//print_r($doubles);
// Write to file.
//print $statements;
file_put_contents('events-2022.data', $statements);
// Write
file_put_contents('uuid_events.json', serialize($uuid_events));