mirror of
https://github.com/DOI-DO/j40-cejst-2.git
synced 2025-08-21 09:31:40 -07:00
Backend change for Zipfile pt. 2 (#469)
* Fixes #303 : adding downloadable zip archive logic * linter recommendations * Pushes data directory to AWS. We'll want to move to use AWS for this ASAP, but this works for now * updating pattern
This commit is contained in:
parent
6eb7382d48
commit
9a9d5fdf7f
8 changed files with 223 additions and 10 deletions
|
@ -1,5 +1,7 @@
|
|||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
@ -119,8 +121,13 @@ def unzip_file_from_url(
|
|||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
logger.info(f"Downloading {file_url}")
|
||||
download = requests.get(file_url, verify=verify)
|
||||
file_contents = download.content
|
||||
response = requests.get(file_url, verify=verify)
|
||||
if response.status_code == 200:
|
||||
file_contents = response.content
|
||||
else:
|
||||
sys.exit(
|
||||
f"HTTP response {response.status_code} from url {file_url}. Info: {response.content}"
|
||||
)
|
||||
|
||||
zip_file_path = download_path / "downloaded.zip"
|
||||
zip_file = open(zip_file_path, "wb")
|
||||
|
@ -152,6 +159,7 @@ def score_folder_cleanup() -> None:
|
|||
logger.info("Initializing all score data")
|
||||
remove_all_from_dir(data_path / "score" / "csv")
|
||||
remove_all_from_dir(data_path / "score" / "geojson")
|
||||
remove_all_from_dir(data_path / "score" / "downloadable")
|
||||
|
||||
|
||||
def temp_folder_cleanup() -> None:
|
||||
|
@ -1176,3 +1184,29 @@ def get_excel_column_name(index: int) -> str:
|
|||
]
|
||||
|
||||
return excel_column_names[index]
|
||||
|
||||
|
||||
def get_zip_info(archive_path: Path) -> list:
|
||||
"""
|
||||
Returns information about a provided archive
|
||||
|
||||
Args:
|
||||
archive_path (pathlib.Path): Path of the archive to be inspected
|
||||
|
||||
Returns:
|
||||
a list of information about every file in the zipfile
|
||||
|
||||
"""
|
||||
zf = zipfile.ZipFile(archive_path)
|
||||
info_list = []
|
||||
for info in zf.infolist():
|
||||
info_dict = {}
|
||||
info_dict["Filename"] = info.filename
|
||||
info_dict["Comment"] = info.comment.decode("utf8")
|
||||
info_dict["Modified"] = datetime.datetime(*info.date_time).isoformat()
|
||||
info_dict["System"] = f"{info.create_system} (0 = Windows, 3 = Unix)"
|
||||
info_dict["ZIP version"] = info.create_version
|
||||
info_dict["Compressed"] = f"{info.compress_size} bytes"
|
||||
info_dict["Uncompressed"] = f"{info.file_size} bytes"
|
||||
info_list.append(info_dict)
|
||||
return info_list
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue