Download src/download_data.py from xuyun/AcidGNet_HCT116: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/datasets/xuyun/AcidGNet_HCT116/resolve/main/src/download_data.py
- Command line
-
hf download hf://datasets/xuyun/AcidGNet_HCT116/src/download_data.py
-
curl -L -o download_data.py https://huggingface.co/datasets/xuyun/AcidGNet_HCT116/resolve/main/src/download_data.py
1.05 kB
| from __future__ import annotations | |
| import hashlib, pathlib, urllib.request | |
| GEO_URL = "https://ftp.ncbi.nlm.nih.gov/geo/series/GSE253nnn/GSE253054/suppl/GSE253054_Normalized_counts_Acidosis.csv.gz" | |
| def sha256(path: pathlib.Path) -> str: | |
| h = hashlib.sha256() | |
| with path.open("rb") as f: | |
| for block in iter(lambda: f.read(1024 * 1024), b""): | |
| h.update(block) | |
| return h.hexdigest() | |
| def download(url: str, dest: pathlib.Path) -> dict: | |
| dest.parent.mkdir(parents=True, exist_ok=True) | |
| if not dest.exists(): | |
| tmp = dest.with_suffix(dest.suffix + ".part") | |
| req = urllib.request.Request(url, headers={"User-Agent":"AcidGNet-CRC/0.1 (public research data downloader)"}) | |
| with urllib.request.urlopen(req, timeout=120) as r, tmp.open("wb") as f: | |
| while True: | |
| chunk = r.read(1024 * 1024) | |
| if not chunk: break | |
| f.write(chunk) | |
| tmp.replace(dest) | |
| return {"path": str(dest), "bytes": dest.stat().st_size, "sha256": sha256(dest), "url": url} | |