@@ -373,10 +373,14 @@ def _extract_map_data(self, map_filename):
373373 map_file = Path (map_filename )
374374 if not map_file .exists ():
375375 print ("file not found ... skiping parsing" )
376- return
376+ return False
377377
378378 e_tree = xml .etree .ElementTree .ElementTree ()
379- root = e_tree .parse (source = map_filename )
379+ try :
380+ root = e_tree .parse (source = map_filename )
381+ except xml .etree .ElementTree .ParseError as err :
382+ print ("Error on parsing " + map_filename + " - " + err .msg )
383+ return False
380384 solar_system_ids = []
381385
382386 # here we are iterating over Ice Belts and adding to Database
@@ -409,6 +413,7 @@ def _extract_map_data(self, map_filename):
409413 cur .execute (query , solar_systems )
410414 cur .close ()
411415 cur .connection .commit ()
416+ return True
412417
413418 def get_all_regions (self ):
414419 """Function to get all regions from SDE and download the svg maps from dotlan"""
@@ -448,15 +453,23 @@ def process(self):
448453 for region in eve_regions :
449454 file_size = 0
450455 map_filepath = Path (self .data_directory ).joinpath ('maps' ).joinpath (str (region [1 ]).replace (' ' , '_' ) + '.svg' )
451- if not map_filepath .exists ():
452- map_url = self .map_url + region [1 ].replace (' ' , '_' ) + ".svg"
453- urlparse (map_url )
454- file_size = MiscUtils .download_file (map_url , str (region [1 ]).replace (' ' , '_' ) + ".svg" )
455- if file_size is None or file_size <= 100 :
456+ for download_try in range (1 ,4 ):
457+ if not map_filepath .exists ():
458+ map_url = self .map_url + region [1 ].replace (' ' , '_' ) + ".svg"
459+ urlparse (map_url )
460+ file_size = MiscUtils .download_file (map_url , str (region [1 ]).replace (' ' , '_' ) + ".svg" )
461+ if file_size is None or file_size <= 100 :
462+ map_filepath .unlink ()
463+ print ("Dotlan: Invalid data was recieved for " + region [1 ])
464+ else :
465+ if not Path (self .data_directory ).joinpath ('maps' ).exists ():
466+ Path (self .data_directory ).joinpath ('maps' ).mkdir ()
467+ shutil .move ( str (region [1 ]).replace (' ' , '_' ) + ".svg" ,map_filepath )
468+ print ("Dotlan: Downloaded Map for " + region [1 ])
469+ print ("Dotlan: parsing data for " + region [1 ])
470+ if not self ._extract_map_data (map_filepath ):
471+ download_try += 1
456472 map_filepath .unlink ()
457- print ("Dotlan: Invalid data was recieved for " + region [1 ])
473+ print ("Dotlan: Invalid data for " + region [1 ] + ", retrying download (" + download_try + ")." )
458474 else :
459- shutil .move ( str (region [1 ]).replace (' ' , '_' ) + ".svg" ,map_filepath )
460- print ("Dotlan: Downloaded Map for " + region [1 ])
461- print ("Dotlan: parsing data for " + region [1 ])
462- self ._extract_map_data (map_filepath )
475+ break
0 commit comments