@@ -253,38 +253,49 @@ function addEventToCountryData(data, country_name, event_id, event_name) {
253253
254254function parse_tee_data_event_status ( data , result ) {
255255
256- if ( result === undefined ) {
257- return
258- }
256+ var parseSuccess = false
257+
258+ if ( result !== undefined ) {
259+
260+ // Reset the event status data to a blank map
261+ data . event_status = { }
262+
263+ var ownerDocument = document . implementation . createHTMLDocument ( 'virtual' ) ;
264+ // Load the results into a virtual document, so that it doesn't attempt to load
265+ // inline scripts etc...
266+ // Solution taken from https://stackoverflow.com/questions/15113910/jquery-parse-html-without-loading-images
267+ // referencing https://api.jquery.com/jQuery/ & https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument
268+ $ ( result , ownerDocument ) . find ( 'div[id=mw-content-text]>table:first' ) . each ( function ( table_index ) {
269+ var content_table = $ ( this )
270+
271+ content_table . find ( 'tbody>tr' ) . each ( function ( row_index ) {
272+ var content_table_row_cell = $ ( 'td' , this )
273+ // Only attempt to parse it if there are enough cells
274+ if ( content_table_row_cell [ 0 ] !== undefined ) {
275+ if ( content_table_row_cell . length >= 5 ) {
276+ var parkrun_info = {
277+ parkrun_name : content_table_row_cell [ 0 ] . innerText . trim ( ) ,
278+ parkrun_event_director : content_table_row_cell [ 1 ] . innerText . trim ( ) ,
279+ parkrun_event_number : content_table_row_cell [ 2 ] . innerText . trim ( ) ,
280+ parkrun_status : content_table_row_cell [ 3 ] . innerText . trim ( ) ,
281+ parkrun_country : content_table_row_cell [ 4 ] . innerText . trim ( )
282+ }
283+ data . event_status [ parkrun_info . parkrun_event_number ] = parkrun_info
284+ // Note that we've parsed at least something successfully.
285+ parseSuccess = true
286+ // console.log(parkrun_info)
287+ }
288+ } else {
289+ console . log ( "Techincal Event Information table row is malformed: " + JSON . stringify ( content_table_row_cell ) )
290+ }
291+ } )
292+ } )
259293
260- // Reset the event status data to a blank map
261- data . event_status = { }
262-
263- var ownerDocument = document . implementation . createHTMLDocument ( 'virtual' ) ;
264- // Load the results into a virtual document, so that it doesn't attempt to load
265- // inline scripts etc...
266- // Solution taken from https://stackoverflow.com/questions/15113910/jquery-parse-html-without-loading-images
267- // referencing https://api.jquery.com/jQuery/ & https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument
268- $ ( result , ownerDocument ) . find ( 'div[id=mw-content-text]>table:first' ) . each ( function ( table_index ) {
269- var content_table = $ ( this )
270-
271- content_table . find ( 'tbody>tr' ) . each ( function ( row_index ) {
272- var content_table_row_cell = $ ( 'td' , this )
273- if ( content_table_row_cell [ 0 ] !== undefined ) {
274- var parkrun_info = {
275- parkrun_name : content_table_row_cell [ 0 ] . innerText . trim ( ) ,
276- parkrun_event_director : content_table_row_cell [ 1 ] . innerText . trim ( ) ,
277- parkrun_event_number : content_table_row_cell [ 2 ] . innerText . trim ( ) ,
278- parkrun_status : content_table_row_cell [ 3 ] . innerText . trim ( ) ,
279- parkrun_country : content_table_row_cell [ 4 ] . innerText . trim ( )
280- }
281- data . event_status [ parkrun_info . parkrun_event_number ] = parkrun_info
282- // console.log(parkrun_info)
283- }
284- } )
285- } )
294+ console . log ( Object . keys ( data . event_status ) . length + " event statuses available" )
295+
296+ }
286297
287- return
298+ return parseSuccess
288299
289300}
290301
@@ -433,9 +444,10 @@ function update_cache_data(data_events, data_tee) {
433444
434445 // If the technical event information has been obtained, then
435446 // lets parse that.
436- // if (data_tee !== null) {
437- parse_tee_data_event_status ( data , data_tee )
438- // }
447+ var parseResult = parse_tee_data_event_status ( data , data_tee )
448+ console . log ( "Techincal Event Information parse result: " + parseResult )
449+ // If the page hasn't been fetched, or the file can't be parsed, parseResult will be false.
450+ // We should do something with that value, like mark that the page should be fetched again.
439451
440452 // This could potentially do nothing if no event info is available
441453 compute_event_status ( data )
0 commit comments