Spaces:
Paused
Paused
File size: 980 Bytes
1ae6115 | 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 | import requests
import os
HEADERS = {"User-Agent": "CrosskeyRagProject contact@example.com"}
RAW_DIR = os.path.join(os.path.dirname(__file__), "..", "data", "raw")
FILES = {
"companyfacts.zip": "https://www.sec.gov/Archives/edgar/daily-index/xbrl/companyfacts.zip",
"submissions.zip": "https://www.sec.gov/Archives/edgar/daily-index/bulkdata/submissions.zip"
}
def download_file(filename, url):
os.makedirs(RAW_DIR, exist_ok=True)
filepath = os.path.join(RAW_DIR, filename)
print(f"Downloading {filename}...")
response = requests.get(url, headers=HEADERS, stream=True)
if response.status_code == 200:
with open(filepath, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f"Saved to {filepath}")
else:
print(f"Failed: {response.status_code}")
if __name__ == "__main__":
for filename, url in FILES.items():
download_file(filename, url)
|