Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Stock Scraper feature #119

Merged
merged 17 commits into from
Oct 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added way for user to save or not data to drive
  • Loading branch information
antoniouaa committed Oct 1, 2020
commit ba76b04353bae93c2a5be606e5d4610253bf3a1f
15 changes: 11 additions & 4 deletions Scripts/Web_Scrappers/s_n_p500/scrape_stocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime, timedelta
from pathlib import Path
import requests
import yfinance
import pandas as pd
Expand Down Expand Up @@ -34,12 +35,18 @@ def fetch_daily_data_for_ticker(symbol):
start_date = end_date - timedelta(weeks=12)
return yfinance.download(symbol, start_date.strftime("%Y-%m-%d"), end_date.strftime("%Y-%m-%d"))

def save_to_drive(filename, dataframe):
out_file = f"{filename}.csv"
out_dir = Path("CSVs")
out_dir.mkdir(parents=True, exist_ok=True)
dataframe.to_csv(out_dir / out_file)

if __name__ == "__main__":
tickers = fetch_ticker_names()
with open("available_tickers.txt", "w") as ticker_f:
for symbol, name in tickers:
ticker_f.write(f"{symbol}, {name}\n")
data = pd.DataFrame()
for symbol, company in tickers:
data = fetch_daily_data_for_ticker(symbol)
data.to_csv(f"CSVs\\{symbol}.csv")
if input(">>> Save to drive: ").lower() in ("y", "yes"):
for symbol, _ in tickers:
data = fetch_daily_data_for_ticker(symbol)
save_to_drive(symbol, data)