Commit 4d17091f authored by Eric Duminil's avatar Eric Duminil
Browse files

Flat extract

parent cea14af4
......@@ -3,7 +3,7 @@ import zipfile
from datetime import datetime
from pathlib import Path
from citygml_download import TMP_DIR, Bundesland, CityGMLWithDate, download_file, download_all_files
from citygml_download import TMP_DIR, Bundesland, CityGMLWithDate, download_all_files, download_file
# Data are available as WFS
# NOTE: Use geopandas or specific WFS lib?
......@@ -22,14 +22,24 @@ BADEN_WUERTTEMBERG = Bundesland(
# NOTE: Slightly different than in 07_hessen.py
class ZipFile(CityGMLWithDate):
@property
def download_folder(self) -> Path:
tmp_folder = TMP_DIR / self.bundesland.name
tmp_folder.mkdir(exist_ok=True)
return tmp_folder
def download(self, tmp_dir: Path = TMP_DIR, max_retries: int = 3, sleep: int = 0) -> bool:
result = super().download(tmp_dir, max_retries, sleep)
if result:
output_folder = self.download_folder
try:
print(f" Extracting {self.filename}")
with zipfile.ZipFile(self.path, "r") as main_zip:
main_zip.extractall(output_folder)
# Flat extract, without directory
for zip_info in main_zip.infolist():
if zip_info.is_dir():
continue
zip_info.filename = Path(zip_info.filename).name
main_zip.extract(zip_info, self.bundesland.download_folder)
except zipfile.BadZipfile:
print(f"🛑 {self.path} is corrupt. Deleting")
self.path.unlink()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment