scriptinghelpers-archive / questions_tar_extract.py
densenet's picture
Upload folder using huggingface_hub
7febd01 verified
Raw
History Blame Contribute Delete
762 Bytes
import tarfile
from pathlib import Path
script_dir = Path(__file__).resolve().parent
scraped_files_root = "questions"
def extract_articles() -> Path:
articles = script_dir / scraped_files_root
if not articles.is_dir():
articles_archive = script_dir / f"{scraped_files_root}.tar.xz"
if not articles_archive.is_file():
raise RuntimeError(f"{scraped_files_root} directory / {scraped_files_root}.tar.xz archive not present in cwd")
with tarfile.open(articles_archive, "r:*") as tar:
tar.extractall()
articles = script_dir / scraped_files_root
if not articles.is_dir():
raise RuntimeError(f"tarfile extraction failed to produce {scraped_files_root} directory")
return articles