Create download_data.py

Need to run the script in the aflow/data path
This commit is contained in:
Zhaoyang Yu 2024-10-21 16:34:48 +08:00
parent c194415b35
commit fe3fca514a

View file

@ -0,0 +1,36 @@
import os
import requests
import tarfile
from tqdm import tqdm
def download_file(url, filename):
response = requests.get(url, stream=True)
total_size = int(response.headers.get('content-length', 0))
block_size = 1024
progress_bar = tqdm(total=total_size, unit='iB', unit_scale=True)
with open(filename, 'wb') as file:
for data in response.iter_content(block_size):
size = file.write(data)
progress_bar.update(size)
progress_bar.close()
def extract_tar_gz(filename, extract_path):
with tarfile.open(filename, 'r:gz') as tar:
tar.extractall(path=extract_path)
url = "https://drive.google.com/uc?export=download&id=1tXp5cLw89egeKRwDuood2TPqoEWd8_C0"
filename = "aflow_data.tar.gz"
extract_path = "./"
print("Downloading data file...")
download_file(url, filename)
print("Extracting data file...")
extract_tar_gz(filename, extract_path)
print("Download and extraction completed.")
# Clean up the compressed file
os.remove(filename)
print(f"Removed {filename}")