Spaces:
Sleeping
Sleeping
File size: 1,119 Bytes
aac9e56 0a6956c aac9e56 0a6956c aac9e56 0a6956c aac9e56 0a6956c aac9e56 0a6956c aac9e56 0a6956c aac9e56 0a6956c aac9e56 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import os
import shutil
import pandas as pd
from pathlib import Path
RAW_DIR = Path("data/raw")
RAW_DIR.mkdir(exist_ok=True)
STOCK_FILE = RAW_DIR / "stock_prices.csv"
def fetch_stock_data():
"""
In cloud environments (Codespaces), Yahoo Finance is blocked.
If stock_prices.csv already exists, reuse it safely.
"""
if STOCK_FILE.exists():
print("Using existing stock_prices.csv (no external fetch)")
return
raise RuntimeError(
"stock_prices.csv not found. "
"Place it manually in data/raw when running in Codespaces."
)
def copy_news_files():
source_dir = Path("data")
target_dir = RAW_DIR
files = ["news_articles.csv", "gnews_data.csv", "reddit_data.csv"]
for f in files:
src = source_dir / f
dst = target_dir / f
if not src.exists():
print(f"[WARN] {src} not found")
continue
if src.resolve() == dst.resolve():
continue
shutil.copy(src, dst)
print(f"Copied {src} → {dst}")
if __name__ == "__main__":
fetch_stock_data()
copy_news_files()
|