@@ -76,18 +76,6 @@ var cache = {
7676 'timeout' : 5000 ,
7777 'last_status' : { }
7878 } ,
79- 'technical_event_information' : {
80- 'raw_data' : undefined ,
81- 'updated_at' : undefined ,
82- 'last_update_attempt' : undefined ,
83- 'updating' : false ,
84- 'max_age' : 3 * 24 * 60 * 60 * 1000 ,
85- 'url' : "https://wiki.parkrun.com/index.php/Technical_Event_Information" ,
86- 'datatype' : 'html' ,
87- 'enabled' : true ,
88- 'timeout' : 5000 ,
89- 'last_status' : { }
90- } ,
9179 'data' : undefined ,
9280 'updated_at' : undefined
9381}
@@ -143,9 +131,6 @@ function get_cache_summary() {
143131 'events' : {
144132 'updated_at' : cache . events . updated_at
145133 } ,
146- 'technical_event_information' : {
147- 'updated_at' : cache . technical_event_information . updated_at
148- }
149134 }
150135 }
151136
@@ -174,7 +159,6 @@ function get_cache_summary() {
174159
175160function clear_cache ( ) {
176161 clear_cache_by_name ( "events" )
177- clear_cache_by_name ( "technical_event_information" )
178162}
179163
180164function clear_cache_by_name ( name ) {
@@ -289,114 +273,14 @@ function addEventToCountryData(data, country_name, event_id, event_name) {
289273 data . countries [ country_name ] [ "child_event_names" ] . push ( event_name )
290274}
291275
292- function parse_tee_data_event_status ( data , result ) {
293-
294- var parseSuccess = false
295-
296- if ( result !== undefined ) {
297-
298- // Reset the event status data to a blank map
299- data . event_status = { }
300-
301- // console.log("Attempting to load the Technical Event Information into a virtual DOM")
302- // var ownerDocument = document.implementation.createHTMLDocument('virtual');
303- // Load the results into a virtual document, so that it doesn't attempt to load
304- // inline scripts etc...
305- // Solution taken from https://stackoverflow.com/questions/15113910/jquery-parse-html-without-loading-images
306- // referencing https://api.jquery.com/jQuery/ & https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument
307-
308- // This ends up with a shed load of errors about:
309- // Refused to apply inline style because it violates the following Content Security Policy directive:
310- // "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-0EZqoz+oBhx7gF4nvY2bSqoGyy4zLjNF+SDQXGp/ZrY='),
311- // or a nonce ('nonce-...') is required to enable inline execution. Note also that 'style-src' was not explicitly set,
312- // so 'default-src' is used as a fallback.
313- // This seems to be because loading the document inlines the styles, which I'd quite happily do away with
314- // if only I knew how to.
315-
316- // I have abandoned using the HTML parser directly as it brings too much baggage, instead
317- // we will parse the wiki page as an XML document until we get to the row we are interested
318- // in, and then only parse that as a HTML document - thus skipping all the scripts and other
319- // junk the page loads in elsewhere and it will be as clean as possible.
320- // This does mean we have to do a few odd things to make a valid HTML doc, but it does mean it
321- // throws no security errors anymore, and we still get the data we want.
322-
323- console . log ( "Attempting to load the Technical Event Information into an XML document" )
324- var xmlDoc = $ . parseXML ( result )
325-
326- $ ( xmlDoc ) . find ( 'div[id=mw-content-text]>table:first' ) . each ( function ( table_index ) {
327- var content_table = $ ( this )
328- // console.log(content_table)
329-
330- content_table . find ( 'tr' ) . each ( function ( row_index ) {
331- // Reconstitute a valid document with a top level tag for the HTML parser
332- var row_html_content = "<tr>" + $ ( this ) . html ( ) + "</tr>"
333- // Parse it into a JQuery object
334- var html_row = $ ( row_html_content )
335- // Find the td elements
336- var content_table_row_cell = $ ( 'td' , html_row )
337- // Only attempt to parse it if there are enough cells
338- if ( content_table_row_cell [ 0 ] !== undefined ) {
339- if ( content_table_row_cell . length >= 5 ) {
340- var parkrun_info = {
341- parkrun_name : content_table_row_cell [ 0 ] . innerText . trim ( ) ,
342- parkrun_event_director : content_table_row_cell [ 1 ] . innerText . trim ( ) ,
343- parkrun_event_number : content_table_row_cell [ 2 ] . innerText . trim ( ) ,
344- parkrun_status : content_table_row_cell [ 3 ] . innerText . trim ( ) ,
345- parkrun_country : content_table_row_cell [ 4 ] . innerText . trim ( )
346- }
347- data . event_status [ parkrun_info . parkrun_event_number ] = parkrun_info
348- // Note that we've parsed at least something successfully.
349- parseSuccess = true
350- // console.log(parkrun_info)
351- }
352- } else {
353- // Don't bother printing that the top row is malformed, it's probably the header,
354- // we'll just flag up if one of the other rows is weird.
355- if ( row_index != 0 ) {
356- console . log ( "Techincal Event Information table row is malformed on row " + row_index + ": " + JSON . stringify ( content_table_row_cell ) )
357- }
358- }
359- } )
360- } )
361- console . log ( "Technical Event Information processing complete" )
362-
363- console . log ( Object . keys ( data . event_status ) . length + " event statuses available" )
364-
365- }
366-
367- return parseSuccess
368-
369- }
370-
371- function compute_event_status ( data ) {
372-
373- if ( data === undefined ) {
374- return
375- }
376-
377- // Loop through the existing geo_data, and supplement it with the
378- // extra event data we have found if there is a match
379- $ . each ( data . events , function ( event_name , event_info ) {
380- if ( data . event_status !== undefined && event_info . id in data . event_status ) {
381- // console.log('Found state '+live_parkrun_event_data[event_info.id].parkrun_status+" for "+event_name)
382- data . events [ event_name ] . status = data . event_status [ event_info . id ] . parkrun_status
383- } else {
384- data . events [ event_name ] . status = 'unknown'
385- }
386- } )
387-
388- return
389-
390- }
391-
392276function get_geo_data ( notify_func , freshen = false ) {
393277 var now = new Date ( )
394278
395279 // Work out if any of the files in 'cache' need updating
396280 // and construct a parallel ajax call to fetch whichever ones we need
397281 // this allows for easy extension in the future by adding data sources
398282 // with not a lot of code changes
399- var data_sources = [ 'events' , 'technical_event_information' ]
283+ var data_sources = [ 'events' ]
400284 var ajax_calls = [ ]
401285 // Make a not if any deferred ajax calls are created
402286 var update_needed = false
@@ -458,7 +342,7 @@ function get_geo_data(notify_func, freshen=false) {
458342 // retrieved data.
459343 $ . when ( ajax_calls [ 0 ] , ajax_calls [ 1 ] ) . done (
460344 // 20191117 - data_geo replaced with data_events
461- function ( data_events , data_tee ) {
345+ function ( data_events ) {
462346
463347 // We absolutely need the events data, without which we can't do
464348 // anything.
@@ -478,37 +362,31 @@ function get_geo_data(notify_func, freshen=false) {
478362 console . log ( 'Fresh data available' )
479363 }
480364
481- // Check if we have technical event information and fall back if not
482- if ( data_tee === undefined ) {
483- data_tee = cache . technical_event_information . raw_data
484- }
485-
486- update_cache_data ( data_events , data_tee )
365+ update_cache_data ( data_events )
487366
488367 notify_geo_data ( notify_func )
489368 return
490369 }
491370 )
492371 } else {
493372 // Just return the cached data
494- console . log ( 'Returning cached data for TEE & Geo Data' )
373+ console . log ( 'Returning cached data for Geo Data' )
495374 notify_geo_data ( notify_func )
496375 }
497376
498377}
499378
500379function regenerate_cache_data ( ) {
501- update_cache_data ( cache . events . raw_data , cache . technical_event_information . raw_data )
380+ update_cache_data ( cache . events . raw_data )
502381}
503382
504- function update_cache_data ( data_events , data_tee ) {
383+ function update_cache_data ( data_events ) {
505384
506385 if ( data_events === undefined ) {
507386 cache . data = {
508387 'valid' : false ,
509388 'data_fetch_status' : {
510- 'events' : cache . events . last_status ,
511- 'event_info' : cache . technical_event_information . last_status
389+ 'events' : cache . events . last_status
512390 }
513391 }
514392 cache . updated_at = undefined
@@ -523,27 +401,13 @@ function update_cache_data(data_events, data_tee) {
523401 'countries' : { } ,
524402 'event_status' : undefined ,
525403 'data_fetch_status' : {
526- 'events' : cache . events . last_status ,
527- 'event_info' : cache . technical_event_information . last_status
404+ 'events' : cache . events . last_status
528405 }
529406 }
530407
531408 // Replace the complicated events/regions parsing with a single call
532409 parse_events ( data , data_events )
533410
534- // If the technical event information has been obtained, then
535- // lets parse that.
536- var parseResult = parse_tee_data_event_status ( data , data_tee )
537- console . log ( "Techincal Event Information parse result: " + parseResult )
538- // If the page hasn't been fetched, or the file can't be parsed, parseResult will be false.
539- // We should do something with that value, like mark that the page should be fetched again.
540-
541- // This could potentially do nothing if no event info is available
542- compute_event_status ( data )
543- // console.log(data)
544- // Create the heirachy of events by region
545- // compute_geo_data_heirachy(data)
546-
547411 // Update the global cache
548412 cache . data = data
549413 cache . updated_at = new Date ( )
@@ -607,10 +471,6 @@ function notify_geo_data(f) {
607471 clear_cache_by_name ( "events" )
608472 done = true
609473 break
610- case "cache-tei-clear" :
611- clear_cache_by_name ( "technical_event_information" )
612- done = true
613- break
614474 case "cache-get" :
615475 if ( cache . data ) {
616476 msg = JSON . stringify ( cache . data , null , 2 )
@@ -632,14 +492,6 @@ function notify_geo_data(f) {
632492 cache . events . enabled = false
633493 done = true
634494 break
635- case "enable-tei" :
636- cache . technical_event_information . enabled = true
637- done = true
638- break
639- case "disable-tei" :
640- cache . technical_event_information . enabled = false
641- done = true
642- break
643495 }
644496 if ( done ) {
645497 sendResponse ( {
0 commit comments