| import os | |
| import zipfile | |
| import requests | |
| from pathlib import Path | |
| def fetch_data(url, data_path, image_path): | |
| if image_path.exists(): | |
| print(f"{image_path} directory exists.") | |
| else: | |
| print(f"Did not find {image_path} directory, creating one...") | |
| image_path.mkdir(parents=True, exist_ok=True) | |
| # Download data | |
| data_zip_path = data_path / "pizza_steak_sushi.zip" | |
| with open(data_zip_path, "wb") as f: | |
| request = requests.get(url) | |
| print("Downloading pizza, steak, sushi data...") | |
| f.write(request.content) | |
| # Unzip pizza, steak, sushi data | |
| with zipfile.ZipFile(data_zip_path, "r") as zip_ref: | |
| print("Unzipping pizza, steak, sushi data...") | |
| zip_ref.extractall(image_path) | |
| # Remove zip file | |
| os.remove(data_zip_path) |