Skip to content

Commit bd2aab3

Browse files
committed
[FIX] script crashed when data directory its not present
[FIX] Script crashed when SVG data its corrupted or incomplete, for now it bypass the file. [FIX] Script crashed when map directory its not present [UPD] improved the algorithm to download the maps to retrie the download if an error happened until 3 retries.
1 parent 92a95b2 commit bd2aab3

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

database_builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def update_as_needed(resource_name):
5555
downloaded_data = download_control(md5_url)
5656

5757
if downloaded_data is not None:
58+
if not Path(".").joinpath("data").exists():
59+
Path(".").joinpath("data").mkdir()
5860
shutil.move(Path('.').joinpath(files[0]),md5_file)
5961
with open(md5_file, 'rt', encoding="UTF-8") as file:
6062
md5.append(file.read())

external_parser.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)