"git@transfer.hft-stuttgart.de:zedflow/test-k1.git" did not exist on "bc7ea410011b11d00a7c6155114e39e34b86ab6e"
Commit 4d17091f authored by Eric Duminil's avatar Eric Duminil
Browse files

Flat extract

parent cea14af4
...@@ -3,7 +3,7 @@ import zipfile ...@@ -3,7 +3,7 @@ import zipfile
from datetime import datetime from datetime import datetime
from pathlib import Path 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 # Data are available as WFS
# NOTE: Use geopandas or specific WFS lib? # NOTE: Use geopandas or specific WFS lib?
...@@ -22,14 +22,24 @@ BADEN_WUERTTEMBERG = Bundesland( ...@@ -22,14 +22,24 @@ BADEN_WUERTTEMBERG = Bundesland(
# NOTE: Slightly different than in 07_hessen.py # NOTE: Slightly different than in 07_hessen.py
class ZipFile(CityGMLWithDate): 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: def download(self, tmp_dir: Path = TMP_DIR, max_retries: int = 3, sleep: int = 0) -> bool:
result = super().download(tmp_dir, max_retries, sleep) result = super().download(tmp_dir, max_retries, sleep)
if result: if result:
output_folder = self.download_folder
try: try:
print(f" Extracting {self.filename}") print(f" Extracting {self.filename}")
with zipfile.ZipFile(self.path, "r") as main_zip: 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: except zipfile.BadZipfile:
print(f"🛑 {self.path} is corrupt. Deleting") print(f"🛑 {self.path} is corrupt. Deleting")
self.path.unlink() 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