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
()
| 59 | |
| 60 | |
| 61 | def 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 | |
| 92 | def forward(): |