MCPcopy Index your code
hub / github.com/robertmartin8/MachineLearningStocks / check_yahoo

Function check_yahoo

current_data.py:61–89  ·  view source on GitHub ↗

Retrieves the stock ticker from the _KeyStats directory, then downloads the html file from yahoo finance. :return: a directory named `forward/` filled with the html files for each ticker

()

Source from the content-addressed store, hash-verified

59
60
61def check_yahoo():
62 """
63 Retrieves the stock ticker from the _KeyStats directory, then downloads the html file from yahoo finance.
64 :return: a directory named `forward/` filled with the html files for each ticker
65 """
66 # Create the directory where we will store the current data
67 if not os.path.exists("forward/"):
68 os.makedirs("forward/")
69
70 # Retrieve a list of tickers from the fundamental data folder
71 ticker_list = os.listdir(statspath)
72
73 # Required in macOS to remove the hidden index file.
74 if ".DS_Store" in ticker_list:
75 ticker_list.remove(".DS_Store")
76
77 for ticker in tqdm(ticker_list, desc="Download progress:", unit="tickers"):
78 try:
79 link = f"http://finance.yahoo.com/quote/{ticker.upper()}/key-statistics"
80 resp = requests.get(link)
81
82 # Write results to forward/
83 save = f"forward/{ticker}.html"
84 with open(save, "w") as file:
85 file.write(resp.text)
86
87 except Exception as e:
88 print(f"{ticker}: {str(e)}\n")
89 time.sleep(2)
90
91
92def forward():

Callers 1

current_data.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected